Scanner formula example

To interpret barcode scans and perform action on a register transaction, a scanner formula must be implemented. Below is an example that uses the barcode string returned from the scanner device and fed to the formula and interpreted to potentially add a charge record. There are 3 entities that matter when working with the scanner formula.

  1. BarcodeData: Data returned as a string from the scanner.
  2. BarcodeSymbology: Symbology of the barcode returned. This is often used if data must be trimmed or to identify what types of barcode this is.
  3. oRegisterTransaction: Current register transaction when the barcode is scanned.
‘This example interprets barcodes prefixed with BLDG and take trailing data as the application
‘number to an application. So barcode BLDG1001 would load all the charges for Building
‘Application with AP Number = 1001. Else, the barcode assumes an 8 character charge code.

Dim res as Hansen.Core.Result =Hansen.Core.Result.Success

IF BarcodeData.StartsWith("BLDG") THEN

dim ex as Hansen.Cashiering.ICharge = ServerApplication.NewComponent("Hansen.Cashiering.Charge", 
oRegisterTransaction.UserInfo) 
dim exc as Hansen.Cashiering.IChargeCollection = ServerApplication.NewComponent
("Hansen.Cashiering.ChargeCollection", oRegisterTransaction.UserInfo)
res += ex.InitializeSearchComponents()
ex.Search_Family = Hansen.Cashiering.ProductFamily.Building
ex.Search_BuildingApplicationNumber = BarcodeData.Replace("BLDG","")
Dim x As New System.Collections.Generic.Dictionary(Of System.String, System.String)
res += ex.SearchInternalCharges(x, exc)
res += oRegisterTransaction.AddCharges(exc)

ELSE IF BarcodeData.Length = 8 THEN

Dim oCharge as Hansen.Cashiering.ICharge = ServerApplication.NewComponent("Hansen.Cashiering.Charge",
oRegisterTransaction.UserInfo)
Dim oChargeSetup as Hansen.Cashiering.IChargeSetup = ServerApplication.NewComponent
("Hansen.Cashiering.ChargeSetup",oRegisterTransaction.UserInfo)
oChargeSetup.ChargeType = BarcodeData
res += oChargeSetup.LoadById()
     oCharge.ConvertExternalChargetoCharge( oCharge,  oChargeSetup )
     res += oRegisterTransaction.AddCharge(oCharge)

END IF

return res