Skip to content

Commit

Permalink
Merge pull request #280 from ymaheshwari1/#279
Browse files Browse the repository at this point in the history
Improved: support to upload csv file when updating inventory(#279)
  • Loading branch information
ymaheshwari1 authored Apr 2, 2024
2 parents 5adb2f6 + 89c9966 commit 857cd53
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
10 changes: 10 additions & 0 deletions src/services/UploadService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ const uploadJsonFile = async (payload: any): Promise <any> => {
...payload
});
}

const uploadAndImportFile = async (payload: any): Promise <any> => {
return api({
url: "uploadAndImportFile",
method: "post",
...payload
});
}

const prepareUploadJsonPayload = (request: UploadRequest) => {
const blob = new Blob([JSON.stringify(request.uploadData)], { type: 'application/json'});
const formData = new FormData();
Expand All @@ -28,5 +37,6 @@ const prepareUploadJsonPayload = (request: UploadRequest) => {

export const UploadService = {
prepareUploadJsonPayload,
uploadAndImportFile,
uploadJsonFile
}
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const jsonToCsv = (file: any, options: JsonToCsvOption = {}) => {
...options.encode
};
const blob = new Blob([csv], {
type: "application/csvcharset=" + encoding
type: "application/csv;charset=" + encoding
});
if (options.download) {
saveAs(blob, options.name ? options.name : "default.csv");
Expand Down
33 changes: 24 additions & 9 deletions src/views/InventoryReview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ import MissingFacilitiesModal from '@/components/MissingFacilitiesModal.vue'
import { defineComponent } from 'vue';
import { mapGetters, useStore } from "vuex";
import { useRouter } from 'vue-router';
import { showToast } from '@/utils';
import { jsonToCsv, showToast } from '@/utils';
import { IonCard, IonCardContent, IonPage, IonHeader, IonToolbar, IonBackButton, IonContent, IonItem, IonThumbnail, IonLabel, IonChip, IonIcon, IonButton, IonButtons, popoverController, IonFab, IonFabButton, modalController, alertController, IonNote, IonSpinner, IonTitle } from '@ionic/vue'
import { businessOutline, calculatorOutline, chevronForwardOutline, ellipsisVerticalOutline, locationOutline, shirtOutline, checkboxOutline, cloudUploadOutline, arrowUndoOutline, warningOutline } from 'ionicons/icons'
import { hasError } from "@/adapter";
export default defineComponent({
name: 'InventoryDetail',
Expand Down Expand Up @@ -223,7 +224,6 @@ export default defineComponent({
this.store.dispatch('stock/updateStockItems', this.stockItems);
},
async save(){
const fileName = this.fileName.replace(".csv", ".json");
const uploadData = this.stockItems.parsed.map((item: any) => {
return {
"facilityId": item.facilityId,
Expand All @@ -232,12 +232,12 @@ export default defineComponent({
"idType": item.identificationTypeId,
"locationSeqId": item.locationSeqId,
"availableQty": item.quantity,
"comments": `Inventory was modified via the Import App by ${this.userProfile.partyName} using the ${fileName} file.`
"comments": `Inventory was modified via the Import App by ${this.userProfile.partyName} using the ${this.fileName} file.`
};
})
const params = {
"configId": "RESET_INVENTORY"
}
} as any
const alert = await alertController.create({
header: translate("Reset inventory"),
message: translate("Make sure all the data you have entered is correct."),
Expand All @@ -249,11 +249,26 @@ export default defineComponent({
{
text: translate("Upload"),
handler: () => {
UploadService.uploadJsonFile(UploadService.prepareUploadJsonPayload({
uploadData,
fileName,
params
})).then(() => {
const data = jsonToCsv(uploadData)
const formData = new FormData();
formData.append("uploadedFile", data, this.fileName);
if(Object.keys(params)) {
for(const key in params) {
formData.append(key, params[key]);
}
}
UploadService.uploadAndImportFile({
data: formData,
headers: {
'Content-Type': 'multipart/form-data;'
}
}).then((resp: any) => {
if(hasError(resp)) {
throw resp.data
}
this.isCsvUploadedSuccessfully = true;
showToast(translate("The inventory has been updated successfully"), [{
text: translate('View'),
Expand Down
7 changes: 6 additions & 1 deletion src/views/PurchaseOrderReview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import MissingSkuModal from "@/components/MissingSkuModal.vue"
import { UploadService } from "@/services/UploadService";
import { showToast } from '@/utils';
import { translate } from "@hotwax/dxp-components";
import { hasError } from '@/adapter';

export default defineComponent({
name: 'PurchaseOrderReview',
Expand Down Expand Up @@ -277,7 +278,11 @@ export default defineComponent({
uploadData,
fileName,
params
})).then(() => {
})).then((resp: any) => {
if(hasError(resp)) {
throw resp.data
}

this.isPOUploadedSuccessfully = true;
showToast(translate("The PO has been uploaded successfully"), [{
text: translate('View'),
Expand Down

0 comments on commit 857cd53

Please sign in to comment.