Skip to content

Commit

Permalink
Implemented: functionality to allow user to add product on scanning (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
amansinghbais committed Mar 22, 2024
1 parent d53dcca commit 88b1428
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Add": "Add",
"Add a product": "Add a product",
"Add to Purchase Order": "Add to Purchase Order",
"Add to Shipment": "Add to Shipment",
Expand Down
8 changes: 4 additions & 4 deletions src/store/modules/order/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ const actions: ActionTree<OrderState, RootState> = {
async updateProductCount({ commit, state }, payload ) {
const item = state.current.items.find((item: any) => item.internalName === payload);

if (item) {
if(item) {
item.quantityAccepted = item.quantityAccepted ? parseInt(item.quantityAccepted) + 1 : 1;
commit(types.ORDER_CURRENT_UPDATED, state.current )
showToast(translate("Scanned successfully.", { itemName: payload }))
} else {
showToast(translate("Scanned item is not present within the shipment:", { itemName: payload }))
return { isUpdated: true, itemName: payload }
}

return { isUpdated: false, itemName: payload }
},
async addOrderItem ({ commit }, payload) {
const product = {
Expand Down
6 changes: 3 additions & 3 deletions src/store/modules/shipment/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ const actions: ActionTree<ShipmentState, RootState> = {
if (item) {
item.quantityAccepted = item.quantityAccepted ? parseInt(item.quantityAccepted) + 1 : 1;
commit(types.SHIPMENT_CURRENT_UPDATED, state);
showToast(translate("Scanned successfully.", { itemName: payload }))
} else {
showToast(translate("Scanned item is not present within the shipment:", { itemName: payload }))
return { isUpdated: true, itemName: payload }
}

return { isUpdated: false, itemName: payload }
},
async setCurrent ({ commit }, payload) {
let resp;
Expand Down
30 changes: 22 additions & 8 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,28 @@ const hasError = (response: any) => {
return typeof response.data != "object" || !!response.data._ERROR_MESSAGE_ || !!response.data._ERROR_MESSAGE_LIST_ || !!response.data.error;
}

const showToast = async (message: string) => {
const toast = await toastController
.create({
message,
duration: 3000,
position: 'bottom',
})
return toast.present();
const showToast = async (message: string, options?: any) => {
const config = {
message,
...options
} as any;

if(!options?.position) config.position = 'bottom';

if(options?.canDismiss) {
config.buttons = [
{
text: translate('Dismiss'),
role: 'cancel',
},
]
}

if(!options?.manualDismiss && !options?.duration) config.duration = 3000;

const toast = await toastController.create(config)
// present toast if manual dismiss is not needed
return !options?.manualDismiss ? toast.present() : toast
}

const copyToClipboard = async (value: string, text?: string) => {
Expand Down
6 changes: 5 additions & 1 deletion src/views/AddProductModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ export default defineComponent({
},
data() {
return {
queryString: ''
queryString: this.selectedSKU
}
},
props: ["selectedSKU"],
computed: {
...mapGetters({
products: 'product/getProducts',
Expand All @@ -98,6 +99,9 @@ export default defineComponent({
facilityLocationsByFacilityId: 'user/getFacilityLocationsByFacilityId'
})
},
mounted() {
if(this.selectedSKU) this.getProducts()
},
methods: {
async getProducts( vSize?: any, vIndex?: any) {
const viewSize = vSize ? vSize : process.env.VUE_APP_VIEW_SIZE;
Expand Down
6 changes: 5 additions & 1 deletion src/views/AddProductToPOModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ export default defineComponent({
},
data() {
return {
queryString: ''
queryString: this.selectedSKU
}
},
props: ["selectedSKU"],
computed: {
...mapGetters({
products: 'product/getProducts',
Expand All @@ -97,6 +98,9 @@ export default defineComponent({
facilityLocationsByFacilityId: 'user/getFacilityLocationsByFacilityId'
})
},
mounted() {
if(this.selectedSKU) this.getProducts()
},
methods: {
async getProducts( vSize?: any, vIndex?: any) {
const viewSize = vSize ? vSize : process.env.VUE_APP_VIEW_SIZE;
Expand Down
26 changes: 25 additions & 1 deletion src/views/PurchaseOrderDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ import LocationPopover from '@/components/LocationPopover.vue'
import ImageModal from '@/components/ImageModal.vue';
import { copyToClipboard, hasError, productHelpers } from '@/utils';
import { Actions, hasPermission } from '@/authorization'
import { showToast } from '@/utils';
export default defineComponent({
name: "PurchaseOrderDetails",
Expand Down Expand Up @@ -258,7 +259,30 @@ export default defineComponent({
},
async updateProductCount(payload: any) {
if(this.queryString) payload = this.queryString
this.store.dispatch('order/updateProductCount', payload)
const result = await this.store.dispatch('order/updateProductCount', payload)
if(result.isUpdated) {
showToast(translate("Scanned successfully.", { itemName: result.itemName }))
} else {
showToast(translate("Scanned item is not present within the shipment:", { itemName: result.itemName }), {
buttons: [{
text: translate('Add'),
handler: async() => {
const modal = await modalController.create({
component: AddProductToPOModal,
componentProps: { selectedSKU: result.itemName }
})
modal.onDidDismiss().then(() => {
this.store.dispatch('product/clearSearchedProducts');
})
return modal.present();
}
}],
duration: 5000
})
}
},
getPOItems(orderType: string) {
if(orderType === 'completed'){
Expand Down
27 changes: 25 additions & 2 deletions src/views/ShipmentDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,32 @@ export default defineComponent({
}
})
},
updateProductCount(payload: any){
async updateProductCount(payload: any){
if(this.queryString) payload = this.queryString
this.store.dispatch('shipment/updateShipmentProductCount', payload)
const result = await this.store.dispatch('shipment/updateShipmentProductCount', payload)
if(result.isUpdated) {
showToast(translate("Scanned successfully.", { itemName: result.itemName }))
} else {
showToast(translate("Scanned item is not present within the shipment:", { itemName: result.itemName }), {
buttons: [{
text: translate('Add'),
handler: async () => {
const modal = await modalController.create({
component: AddProductModal,
componentProps: { selectedSKU: result.itemName }
})
modal.onDidDismiss().then(() => {
this.store.dispatch('product/clearSearchedProducts')
})
return modal.present();
}
}],
duration: 5000
})
}
},
async scanCode () {
const modal = await modalController
Expand Down

0 comments on commit 88b1428

Please sign in to comment.