Skip to content

Commit

Permalink
Merge pull request #364 from amansinghbais/324-add-product-on-scan
Browse files Browse the repository at this point in the history
Implemented: functionality to allow user to add product on scanning (#324)
  • Loading branch information
ymaheshwari1 authored Mar 22, 2024
2 parents d53dcca + 4254ecc commit 5f18909
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 20 deletions.
2 changes: 2 additions & 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 Expand Up @@ -59,6 +60,7 @@
"Password": "Password",
"Pending: item": "Pending: {itemsCount} item",
"Pending: items": "Pending: {itemsCount} items",
"Please provide a valid SKU.": "Please provide a valid SKU.",
"primary identifier": "primary identifier",
"Primary Product Identifier": "Primary Product Identifier",
"Proceed": "Proceed",
Expand Down
6 changes: 3 additions & 3 deletions src/store/modules/order/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ const actions: ActionTree<OrderState, RootState> = {
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 { isProductFound: true }
}

return { isProductFound: false }
},
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 { isProductFound: true }
}

return { isProductFound: false }
},
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 ? 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 ? 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
32 changes: 30 additions & 2 deletions src/views/PurchaseOrderDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ import AddProductToPOModal from '@/views/AddProductToPOModal.vue'
import ClosePurchaseOrderModal from '@/components/ClosePurchaseOrderModal.vue'
import LocationPopover from '@/components/LocationPopover.vue'
import ImageModal from '@/components/ImageModal.vue';
import { copyToClipboard, hasError, productHelpers } from '@/utils';
import { copyToClipboard, hasError, productHelpers, showToast } from '@/utils';
import { Actions, hasPermission } from '@/authorization'
export default defineComponent({
Expand Down Expand Up @@ -258,7 +258,35 @@ export default defineComponent({
},
async updateProductCount(payload: any) {
if(this.queryString) payload = this.queryString
this.store.dispatch('order/updateProductCount', payload)
if(!payload) {
showToast(translate("Please provide a valid SKU."))
return;
}
const result = await this.store.dispatch('order/updateProductCount', payload)
if (result.isProductFound) {
showToast(translate("Scanned successfully.", { itemName: payload }))
} else {
showToast(translate("Scanned item is not present within the shipment:", { itemName: payload }), {
buttons: [{
text: translate('Add'),
handler: async() => {
const modal = await modalController.create({
component: AddProductToPOModal,
componentProps: { selectedSKU: payload }
})
modal.onDidDismiss().then(() => {
this.store.dispatch('product/clearSearchedProducts');
})
return modal.present();
}
}],
duration: 5000
})
}
},
getPOItems(orderType: string) {
if(orderType === 'completed'){
Expand Down
32 changes: 30 additions & 2 deletions src/views/ShipmentDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,37 @@ export default defineComponent({
}
})
},
updateProductCount(payload: any){
async updateProductCount(payload: any){
if(this.queryString) payload = this.queryString
this.store.dispatch('shipment/updateShipmentProductCount', payload)
if(!payload) {
showToast(translate("Please provide a valid SKU."))
return;
}
const result = await this.store.dispatch('shipment/updateShipmentProductCount', payload)
if (result.isProductFound) {
showToast(translate("Scanned successfully.", { itemName: payload }))
} else {
showToast(translate("Scanned item is not present within the shipment:", { itemName: payload }), {
buttons: [{
text: translate('Add'),
handler: async () => {
const modal = await modalController.create({
component: AddProductModal,
componentProps: { selectedSKU: payload }
})
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 5f18909

Please sign in to comment.