From 12c1e41d7473af3ab9acaa41fb891e4874d4eacb Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Tue, 31 Jan 2023 18:38:22 +0530 Subject: [PATCH 1/3] Implemented: support for completed orders(#85zrkm9e3) --- src/locales/en.json | 1 + src/services/OrderService.ts | 9 +++ src/store/modules/order/OrderState.ts | 1 + src/store/modules/order/actions.ts | 75 ++++++++++++++++++++++ src/store/modules/order/getters.ts | 6 ++ src/store/modules/order/index.ts | 4 ++ src/store/modules/order/mutation-types.ts | 1 + src/store/modules/order/mutations.ts | 4 ++ src/utils/solrHelper.ts | 6 +- src/views/Orders.vue | 78 +++++++++++++++++++++-- 10 files changed, 178 insertions(+), 7 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index d4b155117..35cd869e4 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -10,6 +10,7 @@ "City": "City", "Click the backdrop to dismiss.": "Click the backdrop to dismiss.", "Color": "Color", + "Completed": "Completed", "Confirm": "Confirm", "Copied": "Copied { text }", "Copy": "Copy", diff --git a/src/services/OrderService.ts b/src/services/OrderService.ts index a6f6e2833..399eb862f 100644 --- a/src/services/OrderService.ts +++ b/src/services/OrderService.ts @@ -24,6 +24,14 @@ const getPackedOrders = async (payload: any): Promise => { }); } +const getCompletedOrders = async (payload: any): Promise => { + return api({ + url: "solr-query", + method: "post", + data: payload + }); +} + const updateShipment = async (payload: any): Promise => { return api({ url: "updateShipment", @@ -51,6 +59,7 @@ const rejectOrderItem = async (payload: any): Promise => { export const OrderService = { getOpenOrders, getOrderDetails, + getCompletedOrders, getPackedOrders, quickShipEntireShipGroup, rejectOrderItem, diff --git a/src/store/modules/order/OrderState.ts b/src/store/modules/order/OrderState.ts index dfaeeee6c..2e097100f 100644 --- a/src/store/modules/order/OrderState.ts +++ b/src/store/modules/order/OrderState.ts @@ -2,4 +2,5 @@ export default interface OrderState { open: any; current: any; packed: any; + completed: any; } diff --git a/src/store/modules/order/actions.ts b/src/store/modules/order/actions.ts index cd498883d..fc4c26950 100644 --- a/src/store/modules/order/actions.ts +++ b/src/store/modules/order/actions.ts @@ -249,6 +249,81 @@ const actions: ActionTree ={ return resp; }, + async getCompletedOrders ({ commit, state }, payload) { + // Show loader only when new query and not the infinite scroll + if (payload.viewIndex === 0) emitter.emit("presentLoader"); + let resp; + const orderQueryPayload = prepareOrderQuery({ + ...payload, + shipmentMethodTypeId: !store.state.user.preference.showShippingOrders ? 'STOREPICKUP' : '', + orderItemStatusId: "ITEM_COMPLETED", + orderTypeId: 'SALES_ORDER', + docType: 'ORDER' + }) + + try { + resp = await OrderService.getCompletedOrders(orderQueryPayload) + if (resp.status === 200 && resp.data.grouped?.orderId?.ngroups > 0 && !hasError(resp)) { + let orders = resp?.data?.grouped?.orderId?.groups.map((order: any) => { + const orderItem = order.doclist.docs[0] + return { + orderId: orderItem.orderId, + orderName: orderItem.orderName, + // shipmentId: orderItem.shipmentId, //not available in order doc + + customer: { + partyId: orderItem.customerPartyId, + name: orderItem.customerPartyName, + }, + statusId: orderItem.orderStatusId, + parts: order.doclist.docs.reduce((arr: Array, item: any) => { + const currentOrderPart = arr.find((orderPart: any) => orderPart.orderPartSeqId === item.shipGroupSeqId) + if (!currentOrderPart) { + arr.push({ + orderPartSeqId: item.shipGroupSeqId, + shipmentMethodEnum: { + shipmentMethodEnumId: item.shipmentMethodTypeId, + shipmentMethodEnumDesc: item.shipmentMethodTypeDesc + }, + items: [{ + orderItemSeqId: item.orderItemSeqId, + productId: item.productId, + facilityId: item.facilityId + }] + }) + } else { + currentOrderPart.items.push({ + orderItemSeqId: item.orderItemSeqId, + productId: item.productId, + facilityId: item.facilityId + }) + } + + return arr + }, []), + placedDate: orderItem.orderDate + } + }) + this.dispatch('product/getProductInformation', { orders }); + + const total = resp.data.grouped?.orderId?.ngroups; + + if(payload.viewIndex && payload.viewIndex > 0) orders = state.completed.list.concat(orders) + commit(types.ORDER_COMPLETED_UPDATED, { orders, total }) + if (payload.viewIndex === 0) emitter.emit("dismissLoader"); + } else { + commit(types.ORDER_COMPLETED_UPDATED, { orders: {}, total: 0 }) + showToast(translate("Orders Not Found")) + } + emitter.emit("dismissLoader"); + } catch(err) { + console.error(err) + showToast(translate("Something went wrong")) + } + + return resp; + }, + async deliverShipment ({ state, commit }, order) { emitter.emit("presentLoader"); const params = { diff --git a/src/store/modules/order/getters.ts b/src/store/modules/order/getters.ts index 25d8c8296..cf2641b15 100644 --- a/src/store/modules/order/getters.ts +++ b/src/store/modules/order/getters.ts @@ -17,6 +17,12 @@ const getters: GetterTree = { }, isOpenOrdersScrollable: (state) => { return state.open.list.length > 0 && state.open.list.length < state.open.total + }, + getCompletedOrders: (state) => { + return state.completed.list; + }, + isCompletedOrdersScrollable: (state) => { + return state.completed.list.length > 0 && state.completed.list.length < state.completed.total } } diff --git a/src/store/modules/order/index.ts b/src/store/modules/order/index.ts index d4a368df5..d9c51b916 100644 --- a/src/store/modules/order/index.ts +++ b/src/store/modules/order/index.ts @@ -17,6 +17,10 @@ const orderModule: Module = { packed: { list: {}, total: 0 + }, + completed: { + list: {}, + total: 0 } }, getters, diff --git a/src/store/modules/order/mutation-types.ts b/src/store/modules/order/mutation-types.ts index 0cea1e3a1..05dcb522b 100644 --- a/src/store/modules/order/mutation-types.ts +++ b/src/store/modules/order/mutation-types.ts @@ -2,3 +2,4 @@ export const SN_ORDER = 'order' export const ORDER_CURRENT_UPDATED = SN_ORDER + '/CURRENT_UPDATED' export const ORDER_OPEN_UPDATED = SN_ORDER + '/OPEN_UPDATED' export const ORDER_PACKED_UPDATED = SN_ORDER + '/PACKED_UPDATED' +export const ORDER_COMPLETED_UPDATED = SN_ORDER + '/COMPLETED_UPDATED' diff --git a/src/store/modules/order/mutations.ts b/src/store/modules/order/mutations.ts index 2047b9323..b667833a3 100644 --- a/src/store/modules/order/mutations.ts +++ b/src/store/modules/order/mutations.ts @@ -13,6 +13,10 @@ const mutations: MutationTree = { [types.ORDER_PACKED_UPDATED] (state, payload) { state.packed.list = payload.orders state.packed.total = payload.total + }, + [types.ORDER_COMPLETED_UPDATED] (state, payload) { + state.completed.list = payload.orders + state.completed.total = payload.total } } diff --git a/src/utils/solrHelper.ts b/src/utils/solrHelper.ts index 24a382574..eb5970ad3 100644 --- a/src/utils/solrHelper.ts +++ b/src/utils/solrHelper.ts @@ -15,7 +15,7 @@ const prepareOrderQuery = (params: any) => { "start": viewIndex * viewSize }, "query":"(*:*)", - "filter": ["docType: OISGIR"] + "filter": [`docType: ${params.docType ? params.docType : 'OISGIR'}`] } } as any @@ -61,6 +61,10 @@ const prepareOrderQuery = (params: any) => { payload.json.filter.push(`orderId: ${params.orderId}`) } + if(params.orderItemStatusId) { + payload.json.filter.push(`orderItemStatusId: ${params.orderItemStatusId}`) + } + return payload } diff --git a/src/views/Orders.vue b/src/views/Orders.vue index 9c1a5a022..9e5f1a5fb 100644 --- a/src/views/Orders.vue +++ b/src/views/Orders.vue @@ -14,6 +14,9 @@ {{ $t("Packed") }} + + {{ $t("Completed") }} + @@ -95,10 +98,40 @@ +
+
+ + + +

{{ order.customer.name }}

+

{{ order.orderName ? order.orderName : order.orderId }}

+
+ {{ timeFromNow(order.placedDate) }} +
+ + + + + + {{ order.customer.phoneNumber }} + + {{ $t("Copy") }} + + + + + {{ order.customer.email }} + + {{ $t("Copy") }} + + +
+
+
- + @@ -171,9 +204,11 @@ export default defineComponent({ ...mapGetters({ orders: 'order/getOpenOrders', packedOrders: 'order/getPackedOrders', + completedOrders: 'order/getCompletedOrders', currentFacility: 'user/getCurrentFacility', isPackedOrdersScrollable: 'order/isPackedOrdersScrollable', isOpenOrdersScrollable: 'order/isOpenOrdersScrollable', + isCompletedOrdersScrollable: 'order/isCompletedOrdersScrollable', showPackingSlip: 'user/showPackingSlip' }) }, @@ -220,8 +255,10 @@ export default defineComponent({ async refreshOrders(event: any) { if(this.segmentSelected === 'open') { this.getPickupOrders().then(() => { event.target.complete() }); - } else { + } else if (this.segmentSelected === 'packed') { this.getPackedOrders().then(() => { event.target.complete() }); + } else { + this.getCompletedOrders().then(() => { event.target.complete() }); } }, async viewOrder (order: any, part: any) { @@ -243,6 +280,12 @@ export default defineComponent({ await this.store.dispatch("order/getPackedOrders", { viewSize, viewIndex, queryString: this.queryString, facilityId: this.currentFacility.facilityId }); }, + async getCompletedOrders (vSize?: any, vIndex?: any) { + const viewSize = vSize ? vSize : process.env.VUE_APP_VIEW_SIZE; + const viewIndex = vIndex ? vIndex : 0; + + await this.store.dispatch("order/getCompletedOrders", { viewSize, viewIndex, queryString: this.queryString, facilityId: this.currentFacility.facilityId }); + }, async loadMoreProducts (event: any) { if (this.segmentSelected === 'open') { this.getPickupOrders( @@ -251,13 +294,20 @@ export default defineComponent({ ).then(() => { event.target.complete(); }) - } else { + } else if (this.segmentSelected === 'packed') { this.getPackedOrders( undefined, Math.ceil(this.packedOrders.length / process.env.VUE_APP_VIEW_SIZE).toString() ).then(() => { event.target.complete(); }) + } else { + this.getCompletedOrders( + undefined, + Math.ceil(this.completedOrders.length / process.env.VUE_APP_VIEW_SIZE).toString() + ).then(() => { + event.target.complete(); + }) } }, async readyForPickup (order: any, part: any) { @@ -287,7 +337,14 @@ export default defineComponent({ segmentChanged (e: CustomEvent) { this.queryString = '' this.segmentSelected = e.detail.value - this.segmentSelected === 'open' ? this.getPickupOrders() : this.getPackedOrders(); + + if(this.segmentSelected === 'open') { + this.getPickupOrders() + } else if(this.segmentSelected === 'packed') { + this.getPackedOrders() + } else { + this.getCompletedOrders() + } }, getShipGroups (items: any) { // To get unique shipGroup, further it will use on ion-card iteration @@ -307,8 +364,10 @@ export default defineComponent({ async searchOrders() { if(this.segmentSelected === 'open') { this.getPickupOrders() - } else { + } else if(this.segmentSelected === 'packed') { this.getPackedOrders() + } else { + this.getCompletedOrders() } }, selectSearchBarText(event: any) { @@ -319,7 +378,14 @@ export default defineComponent({ }, ionViewWillEnter () { this.queryString = ''; - this.segmentSelected === 'open' ? this.getPickupOrders() : this.getPackedOrders(); + + if(this.segmentSelected === 'open') { + this.getPickupOrders() + } else if(this.segmentSelected === 'packed') { + this.getPackedOrders() + } else { + this.getCompletedOrders() + } }, setup () { const router = useRouter(); From 3c31cec1d9ea8098d924574cf67423a662920407 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Tue, 31 Jan 2023 19:12:44 +0530 Subject: [PATCH 2/3] Improved: code to group orders on the basis of orderId and clear the completed orders(#85zrkm9e3) --- src/store/modules/order/actions.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/store/modules/order/actions.ts b/src/store/modules/order/actions.ts index fc4c26950..259e07901 100644 --- a/src/store/modules/order/actions.ts +++ b/src/store/modules/order/actions.ts @@ -269,22 +269,16 @@ const actions: ActionTree ={ return { orderId: orderItem.orderId, orderName: orderItem.orderName, - // shipmentId: orderItem.shipmentId, //not available in order doc - customer: { partyId: orderItem.customerPartyId, name: orderItem.customerPartyName, }, statusId: orderItem.orderStatusId, parts: order.doclist.docs.reduce((arr: Array, item: any) => { - const currentOrderPart = arr.find((orderPart: any) => orderPart.orderPartSeqId === item.shipGroupSeqId) + const currentOrderPart = arr.find((orderPart: any) => orderPart.orderId === item.orderId) if (!currentOrderPart) { arr.push({ - orderPartSeqId: item.shipGroupSeqId, - shipmentMethodEnum: { - shipmentMethodEnumId: item.shipmentMethodTypeId, - shipmentMethodEnumDesc: item.shipmentMethodTypeDesc - }, + orderId: item.orderId, items: [{ orderItemSeqId: item.orderItemSeqId, productId: item.productId, @@ -472,6 +466,7 @@ const actions: ActionTree ={ clearOrders ({ commit }) { commit(types.ORDER_OPEN_UPDATED, {orders: {} , total: 0}) commit(types.ORDER_PACKED_UPDATED, {orders: {} , total: 0}) + commit(types.ORDER_COMPLETED_UPDATED, {orders: {} , total: 0}) } } From c5043e637d55a06264dba18ce127bd773c03ab5f Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Tue, 31 Jan 2023 19:36:32 +0530 Subject: [PATCH 3/3] Improved: code to use the seqId for creating parts and defined a separate method to get tge items(#85zrkm9e3) --- src/store/modules/order/actions.ts | 4 ++-- src/views/Orders.vue | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/store/modules/order/actions.ts b/src/store/modules/order/actions.ts index 259e07901..e119bbb3c 100644 --- a/src/store/modules/order/actions.ts +++ b/src/store/modules/order/actions.ts @@ -275,10 +275,10 @@ const actions: ActionTree ={ }, statusId: orderItem.orderStatusId, parts: order.doclist.docs.reduce((arr: Array, item: any) => { - const currentOrderPart = arr.find((orderPart: any) => orderPart.orderId === item.orderId) + const currentOrderPart = arr.find((orderPart: any) => orderPart.orderPartSeqId === item.shipGroupSeqId) if (!currentOrderPart) { arr.push({ - orderId: item.orderId, + orderPartSeqId: item.shipGroupSeqId, items: [{ orderItemSeqId: item.orderItemSeqId, productId: item.productId, diff --git a/src/views/Orders.vue b/src/views/Orders.vue index 9e5f1a5fb..95f280ba9 100644 --- a/src/views/Orders.vue +++ b/src/views/Orders.vue @@ -100,7 +100,7 @@
- +

{{ order.customer.name }}

@@ -109,7 +109,7 @@ {{ timeFromNow(order.placedDate) }}
- + @@ -375,6 +375,12 @@ export default defineComponent({ element.select(); }) }, + getOrderItems(orderParts: any) { + return orderParts.reduce((items: Array, part: any) => { + part.items.map((item: any) => items.push(item)) + return items; + }, []) + } }, ionViewWillEnter () { this.queryString = '';