Created
September 19, 2022 16:47
-
-
Save ThianHooi/a79a412cd8cd3bd388c9e84ca1066b12 to your computer and use it in GitHub Desktop.
[Supplier Portal] - Script for getting Excel Header to DB Fields
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
const poLaymanToKey = { | |
'Supplier Code': 'SUP_CODE', | |
'Purchase Order number': 'PO_NUM', | |
'Purchase Order Status ': 'PO_STATUS', | |
'Purchase Order Type ': 'PO_TYPE', | |
'Purchase Order Type Description': 'PO_TYPE_D', | |
'Purchase Order Header Text': 'PO_DESCR', | |
'Purchasing Org': 'PU_ORG', | |
'Purchasing Group': 'PU_GROUP', | |
'Company Code': 'PO_COMP', | |
'Purchase Order Creation Date': 'PO_CRTD', | |
'Purchase Order Creation Time': 'PO_CRTT', | |
'Purchase Order Creator': 'PO_CREA', | |
'Purchase Order Creator Name': 'PO_CREA_D', | |
Currency: 'PO_CURR', | |
'Purchase Order Total Amount ': 'PO_TOTAL', | |
'PO Handler ': 'PO_HANDLER', | |
'One time vendor': 'PO_ONE_TIME_S', | |
'Supplier Name': 'PO_SUPPLIER', | |
'Ship-To Address': 'PO_SHIP_TO', | |
'Customer Name': 'PO_CUSTOMER_NAME', | |
'Payment Term': 'PO_PAYMENT_TERM', | |
'Payment Term Decription': 'PO_PAYMENT_TERM_D', | |
'Purchase Document Category': 'PO_DOC_CAT', | |
'Purchase Document Category Description': 'PO_DOC_CAT_D', | |
'Delivery Date ': 'PO_DELIVERY', | |
'Line Item Number': 'PO_ITEM', | |
'Material Number': 'MATERIAL', | |
'Material Descriptions': 'DESCR', | |
Quantity: 'QUANTITY', | |
'Unit of Measure': 'UOM', | |
'Unit of Measure Descriptions': 'UOM_D', | |
'Unit Price': 'UPRICE', | |
'Total Price': 'TPRICE', | |
'Received Quantity': 'GR_QUANT', | |
'Receiving Status': 'GR_STATUS', | |
'Tax Code': 'TAX_CODE', | |
'Tax Code Description': 'TAX_CODE_D', | |
'Cost Center': 'COSTC', | |
'Cost Center Descriptions': 'COSTC_D', | |
'Profit Center': 'PROFC', | |
'Profit Center Descriptions': 'PROFC_D', | |
Plant: 'PLANT', | |
'Plant Description': 'PLANT_D', | |
'Storage Location': 'SLOC', | |
'Storage Location Description': 'SLOC_D', | |
'Delivery Date _1': 'PO_DELIVERY', | |
'Material/Product Group Code': 'MAT_GROUP', | |
'Material/Product Group Description': 'MAT_GROUP_D', | |
}; | |
const jsonKeyToPurchaseOrderField = { | |
'Supplier Code': 'supplierId', | |
'Purchase Order number': 'poNumber', | |
'Purchase Order Type': 'type', | |
'Purchase Order Type Description': 'typeDescription', | |
'Purchase Order Header Text': 'description', | |
'Purchasing Org': 'purchasingOrganisation', | |
'Purchasing Group': 'purchasingGroup', | |
'Company Code': 'companyCode', | |
'Purchase Order Creator': 'creatorAlias', | |
'Purchase Order Creator Name': 'creatorName', | |
Currency: 'currencyCode', | |
'Purchase Order Total Amount': 'totalPrice', | |
'PO Handler': 'handler', | |
'Supplier Name': 'supplierName', | |
'Ship-To Address': 'deliveryAddress', | |
'Customer Name': 'customerName', | |
'Payment Term': 'paymentTerm', | |
'Payment Term Description': 'paymentTermDescription', | |
'Purchase Document Category': 'documentCategory', | |
'Purchase Document Category Description': 'documentCategoryDescription', | |
}; | |
const jsonKeyToPurchaseOrderProductField = { | |
'Line Item Number': 'productId', | |
'Material Number': 'material', | |
'Material Descriptions': 'description', | |
Quantity: 'quantity', | |
'Unit of Measure': 'unitOfMeasure', | |
'Unit of Measure Descriptions': 'unitOfMeasureDescription', | |
'Unit Price': 'unitPrice', | |
'Total Price': 'totalPrice', | |
'Received Quantity': 'receivedQuantity', | |
// todo(ooi): store proper status | |
// 'Receiving Status': 'receivingStatus', | |
'Tax Code': 'taxCode', | |
'Tax Code Description': 'taxCodeDescription', | |
'Cost Center': 'costCenter', | |
'Cost Center Descriptions': 'costCenterDescription', | |
'Profit Center': 'profitCenter', | |
'Profit Center Descriptions': 'profitCenterDescription', | |
Plant: 'plant', | |
'Plant Description': 'plantDescription', | |
'Storage Location': 'storageLocation', | |
'Storage Location Description': 'storageLocationDescription', | |
// 'Delivery Date': 'deliveryDate', | |
'Material/Product Group Code': 'materialGroup', | |
'Material/Product Group Description': 'materialGroupDescription', | |
}; | |
const poKeyToDbFields = Object.entries(poLaymanToKey).reduce( | |
(previousValue, [key, value]) => { | |
const dbField = jsonKeyToPurchaseOrderField[key]; | |
if (!dbField) return previousValue; | |
return { | |
...previousValue, | |
[value]: dbField, | |
}; | |
}, | |
{} | |
); | |
const poProductKeyToDbFields = Object.entries(poLaymanToKey).reduce( | |
(previousValue, [key, value]) => { | |
const dbField = jsonKeyToPurchaseOrderProductField[key]; | |
if (!dbField) return previousValue; | |
return { | |
...previousValue, | |
[value]: dbField, | |
}; | |
}, | |
{} | |
); | |
console.log('===================================='); | |
console.log(poKeyToDbFields); | |
console.log(poProductKeyToDbFields); | |
console.log(Object.keys(poProductKeyToDbFields).length); | |
console.log(Object.keys(jsonKeyToPurchaseOrderProductField).length); | |
console.log('===================================='); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment