We will be getting data from JAR/WAR library on the same computers to be used to update our purchases module, now instead of capturing the received data manually I am thinking of trapping the data directly from Json into the related tables, that is tblpurchases and tblpurchasesdetails , this way we will surely avoid mistakes or human errors.
Now since at the moment the JAR/WAR library is not yet available, so while waiting, I just want to practice on the Json data in the notepad attached below and see if it can be moved into the mentioned related tables above that is tblpurchases and tblpurchasesdetails . I have provided a near complete VBA though not perfect but to give an idea of what is required:
Now since at the moment the JAR/WAR library is not yet available, so while waiting, I just want to practice on the Json data in the notepad attached below and see if it can be moved into the mentioned related tables above that is tblpurchases and tblpurchasesdetails . I have provided a near complete VBA though not perfect but to give an idea of what is required:
Code:
Private Sub CmdJsondata_Click()
Dim db As dao.Database
Dim json As Object
Dim Details As Variant
Dim strDataAudit As String
Dim JsonAPI As String
Dim Z As Long
Dim rst As Recordset
Dim rs As Recordset
'Receipt Json from (JAR/WAR)Libray
'For demo purpose let us use the attached notepad to get the the data in those field into the related tables
'strDataAudit = Text.txt
'Processing data from the string above
strDataAudit = "C:\Users\chris.hankwembo\Desktop\Testing\Json.txt"
Set db = CurrentDb
Set rst = db.OpenRecordset("tblpurchases", dbOpenDynaset) 'Im not sure here I'm just guesing
Set json = JsonConverter.ParseJson(strDataAudit)
'Process data.even here I'm not 100% sure on the arranged field whether the data can be transfered
For Each Details In json
rs.AddNew
rs![resultDate] = Details("resultDate")
rs![customerTpin] = Details("customerTpin")
rs![customerBhfId] = Details("customerBhfId")
rs![sarNo] = Details("sarNo")
rs![ocrnDate] = Details("ocrnDate")
rs![totItemCnt] = Details("totItemCnt")
rs![totTaxblAmt] = Details("totTaxblAmt")
rs![totTaxAmt] = Details("totTaxAmt")
rs![totAmt] = Details("totAmt")
rs![remark] = Details("remark")
rs.Update
Next
rs.Close
Set rs = Nothing
Set db = Nothing
Set json = Nothing
Set Details = Nothing
End Sub
Code:
{
"resultCd": "000",
"resultMsg": "It is succeeded",
"resultDt": "20231120200723",
"data": {
"stockList": [
{
"custTpin": "9999911300",
"custBhfId": "00",
"sarNo": 6,
"ocrnDt": "20231120",
"totItemCnt": 1,
"totTaxblAmt": 1800000,
"totTaxAmt": 274576.27,
"totAmt": 1800000,
"remark": null,
"itemList": [
{
"itemSeq": 1,
"itemCd": "KR2BZX0000001",
"itemClsCd": "1110162100",
"itemNm": "Grocery_Item#1",
"bcd": "8801234567051",
"pkgUnitCd": "BZ",
"pkg": 0,
"qtyUnitCd": "CA",
"qty": 450,
"itemExprDt": null,
"prc": 4000,
"splyAmt": 1800000,
"totDcAmt": 0,
"taxblAmt": 1800000,
"taxTyCd": "B",
"taxAmt": 274576.27,
"totAmt": 1800000
}
]
},
{
"custTpin": "9999911300",
"custBhfId": "00",
"sarNo": 59,
"ocrnDt": "20231120",
"totItemCnt": 1,
"totTaxblAmt": 660000,
"totTaxAmt": 100677.97,
"totAmt": 660000,
"remark": null,
"itemList": [
{
"itemSeq": 1,
"itemCd": "KR2AMXCRX0000001",
"itemClsCd": "1110151600",
"itemNm": "sample_nudle#1",
"bcd": "8801234567001",
"pkgUnitCd": "AM",
"pkg": 0,
"qtyUnitCd": "CR",
"qty": 600,
"itemExprDt": null,
"prc": 1100,
"splyAmt": 660000,
"totDcAmt": 0,
"taxblAmt": 660000,
"taxTyCd": "B",
"taxAmt": 100677.97,
"totAmt": 660000
}
]
}
]
}
}
Attachments
Last edited: