Imports System Imports System.Collections.Generic Imports System.Text Imports System.Web Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.IO Imports ONESOURCEApi Imports MTSApi Imports MTSApi.API 'Added by Kimmy Wang 1/5/2016 Imports MTSApi.Implementation _ _ _ Public Class Service Inherits System.Web.Services.WebService _ Public Function VerifyAddress(ByVal input As String) As String Dim av As ISingleAddressValidator Dim inputAddress As ISingleAddressInfo Dim outputAddress As ISingleValidationResponseInfo Dim a As Address Dim str As String Dim iAddress As Integer = 0 Try WriteLog("IN|VerifyAddress|" & input) a = New Address a.parse(input) av = New SingleAddressValidator inputAddress = New SingleAddressInfo inputAddress.Country = "USA" inputAddress.Address1 = a.address1 inputAddress.City = a.city inputAddress.Region = a.state inputAddress.PostalCode = a.zip validate_address: outputAddress = av.ValidateAddress(inputAddress) 'str = outputAddress.status & "|" & outputaddress.description If outputAddress.IsSuccess Then str = "OK1|" & outputAddress.Address.Address1 & "|" & outputAddress.Address.City & "|" & outputAddress.Address.Region & "|" & outputAddress.Address.PostalCode For i As Integer = 0 To outputAddress.MessageCount - 1 str += outputAddress.Message(i).Description & "|" Next Else iAddress += 1 If iAddress = 1 Then inputAddress.Address1 = a.address2 GoTo validate_address End If If iAddress = 2 Then inputAddress.Address1 = a.address3 End If str = outputAddress.IsSuccess For i As Integer = 0 To outputAddress.MessageCount - 1 str += "|" & outputAddress.Message(i).Description Next End If av = Nothing WriteLog("OUT|VerifyAddress|" & str) Return str Catch ex As Exception WriteLog("ERROR|VerifyAddress|" & input & "|" & ex.Message) Return ex.Message End Try End Function _ Public Function VerifyAddressBatch(ByVal input As String) As String Dim av As IAddressValidator Dim reqInfo As MTSApi.IValidationRequestInfo Dim addressInfo As MTSApi.IValidationRequestAddressInfo Dim responseInfo As MTSApi.IResponseInfo Dim a As Address Try a = New Address a.parse(input) av = New AddressValidator reqInfo = New MTSApi.ValidationRequestInfo av.CreateRequest(reqInfo) addressInfo = New MTSApi.ValidationRequestAddressInfo addressInfo.Country = "USA" addressInfo.Address1 = a.address1 addressInfo.City = a.city addressInfo.Region = a.state addressInfo.PostalCode = a.zip av.AddAddress(addressInfo) responseInfo = av.Send If responseInfo.IsSuccess Then Dim outAddress As MTSApi.IValidatedAddressInfo outAddress = av.NextAddress Return responseInfo.IsSuccess & "|" & outAddress.ResponseAddresses(0).Address1 & "|" & outAddress.ResponseAddresses(0).City & "|" & outAddress.ResponseAddresses(0).Region & "|" & outAddress.ResponseAddresses(0).PostalCode End If Return responseInfo.IsSuccess Catch ex As Exception Return ex.Message End Try End Function _ Public Function AddressParseTest(ByVal input As String) As String Dim a As Address Try a = New Address a.parse(input) Return a.getValues Catch ex As Exception Return ex.Message End Try End Function _ Public Function Invoice(ByVal input As String) As String WriteLog("Testing for input parameters") 'Added by Kimmy Wang 2/18/2014 Dim calc As MTSApi.ITaxCalculatorInterface Dim request As MTSApi.IRequestInfo Dim response As MTSApi.IResponseInfo Dim id As String Dim inputDoc As IDocumentInfo Dim outputDoc As MTSApi.IOutputDocumentInfo Dim inputLine As ILineInfo Dim outputLine As MTSApi.IOutputLineInfo Dim outputDetailInfo As MTSApi.IOutputDetailInfo Dim outputZoneSummaryInfo As MTSApi.IZoneSummaryInfo Dim inv As InvoiceItem Dim c As CompanyInfo Dim str As String Dim shipToPostalCode As String 'Added By Kimmy Wang 02/18/2014 'Dim shipToGeoCode As String 'Added By Kimmy Wang 02/18/2014 comment out by Kimmy Wang 1/5/2016 due to the new structure of APi Try 'WriteLog("Testing for input parameters") WriteLog("IN|Invoice|" & input) 'parse all invoice info from input string inv = New InvoiceItem inv.parse(input) ' Check Kimmy 2/18/2014 WriteLog("***Input 9 digit zip code: ") ' Added postal code and geo code parsing 2/18/2014 by Kimmy Wang shipToPostalCode = inv.to_zip.Substring(0, 5) ' shipToGeoCode = inv.to_zip.Substring(6, 9) WriteLog("***SHIP TO POSTALCODE: " & shipToPostalCode) ' WriteLog("***SHIP TO GEOCODE: " & shipToGeoCode) 'load company info from the config file c = New CompanyInfo c.Load(inv.company) calc = New TaxCalculator request = New RequestInfo 'already exit in old - kimmy 12/10/2015 response = New ResponseInfo 'Added by Kimmy Wang on 12/15/2015 request.HostSystemNumber = "sabrix.com|SELLER|MRIMACOLA" request.CallingClient = "Project 5.1.000.258" 'Added by Kimmy Wang on 12/10/2015 request.CallingSource = "SABRIX Interface" 'Added by Kimmy Wang on 12/10/2015 request.CallingSystemNumber = "USA" 'Added by Kimmy Wang on 12/10/2015 request.CallingUser = Environment.UserName 'Added by Kimmy Wang on 12/10/2015 request.DbVersion = "SQL 2012" 'Added by Kimmy Wang on 12/10/2015 request.ErpVersion = "Macola 9.6.1" 'Added by Kimmy Wang on 12/10/2015 request.HostRequestLoggingId = "1" 'Added by Kimmy Wang on 12/10/2015 request.IntegrationVersion = "5.1.000.258" 'Added by Kimmy Wang on 12/10/2015 response.HostRequestId = "1" 'Added by Kimmy Wang on 12/15/2015 request.ExternalCompanyId = c.ExternalCompanyId request.UserName = c.UserName request.Password = c.Password id = calc.CreateRequest(request) inputDoc = New DocumentInfo inputDoc.CompanyRole = "Seller" inputDoc.AmountType = "GrossAmountBased" 'Added by Kimmy Wang 12/15/2015 new required field inputDoc.CurrencyCode = "USD" 'Added by Kimmy Wang 12/15/2015 new required field inputDoc.DocumentNumber = inv.order_number 'inputDoc.PartnerNumber = inv.customer 'KIMMY 12/10 not in DocumentInfo any more it is in line info now If inv.invoice_date.Trim.Length > 0 Then inputDoc.DocumentDate = inv.invoice_date Else inputDoc.DocumentDate = Now End If If inv.invoice_date.Trim.Length > 0 Then 'Added by Fiscal Date Kimmy Wang 12/17/2015 as it is required field inputDoc.FiscalDate = inv.invoice_date Else inputDoc.DocumentDate = Now End If 'inputDoc.IsEditDocument = True 'KIMMY 12/10 can't find in new MTSApi (ONESOURCEApi) inputDoc.IsAuditResult = IIf(inv.write_to_database = "Y", True, False) 'inputDoc.IsExempt = IIf(inv.exempt_yn = "Y", True, False) inputDoc.DocumentType = IIf(inv.write_to_database = "Y", "SalesInvoice", "SalesOrder") Dim shipFrom = New TaxAddressInfo(New Constants().ShipFromAddress) 'Added by Kimmy wang 1/5/2016 to pass ship from to DocumentInfo shipFrom.Country = inv.from_country 'Added by Kimmy wang 12/26 shipFrom.Region = inv.from_state 'Added by Kimmy wang 12/26 shipFrom.City = inv.from_city 'Added by Kimmy wang 12/26 shipFrom.PostalCode = inv.from_zip 'Added by Kimmy wang 12/26 shipFrom.PartnerNumber = inv.customer 'Added by Kimmy wang 12/26 inputDoc.AddAddress(shipFrom) 'Added by Kimmy wang 12/26 Dim shipto = New TaxAddressInfo(New Constants().ShipToAddress) 'Added by Kimmy Wang on 1/5/2016 to pass the ship to to DocumentInfo shipto.Country = inv.to_country 'Added by Kimmy wang 12/26 shipto.Region = inv.to_state 'Added by Kimmy wang 12/26 shipto.City = inv.to_city 'Added by Kimmy wang 12/26 shipto.PostalCode = shipToPostalCode 'Added by Kimmy wang 12/26 ' shipto.GeoCode = inv.to_zip.Substring(5) 'comment out by Kimmy Wang 1/5/2016 If inv.to_zip.Trim.Length > 5 Then 'Added by Kimmy wang 1/05 to pass the Geo Code shipto.GeoCode = inv.to_zip.Substring(5) Else : shipto.GeoCode = Nothing End If shipto.PartnerNumber = inv.customer 'Added by Kimmy wang 12/26 inputDoc.AddAddress(shipto) 'Added by Kimmy Wang 12/26 calc.AddDocument(inputDoc) 'inputLine.IsExempt = IIf(inv.exempt_yn = "Y", True, False) inputLine = New LineInfo inputLine.LineNumber = inv.line_number inputLine.GrossAmount = inv.extended_price inputLine.ProductCode = inv.product_code inputLine.PartNumber = inv.item inputLine.Quantity = 1 inputLine.UnitOfMeasure = inv.UOM 'Added by Kimmy Wang 12/11/2015 since it is a required filed now 'calc.AddLine(inputLine) 'calc.AddLine(CreateLine(inv.extended_price, inv.line_number)) ' 1/22/2016 Kimmy per Steve, but not working calc.AddLine(CreateLine(50, "1", "1", "EA")) '1/22/2016 kimmy per Steve, but not working. Complain about line number calc.AddLine(CreateLine(100, "2", "1", "EA")) 'outputLine = calc.NextLine ' added by kimmy 1/22/2016. Without go t next document, this won't go to next line 'calc.NextLine() ' added by kimmy 1/22/2016. By adding this, system only create 1 request, but won't go to next line response = calc.Send WriteLog("OUT|Invoice|" & response.Code) If response.IsSuccess = True Then outputDoc = calc.NextDocument 'added by kimmy 1/22/2016. By adding this, system only create 1 request, but won't go to next line outputLine = calc.NextLine 'comment out by Kimmy 1/25/2016 because This creats 2nd request for new line outputDetailInfo = calc.NextDetail outputZoneSummaryInfo = calc.NextZoneSummary str = "OK" & Math.Round(CDec(outputLine.EffectiveTaxRate), 6).ToString("0.000000") & outputLine.TaxAmount '& "|" & outputDetailInfo.ExemptAmount & "|" & outputDetailInfo.AuthorityType & "|" & outputZoneSummaryInfo.ExemptAmount WriteLog("OUT|Invoice|" & str) Return str Else Return response.Description End If calc = Nothing Catch ex As Exception WriteLog("ERROR|Invoice|" & input & "|" & ex.Message) Return ex.Message End Try End Function 'Added this function by Kimmy 1/22/2016 per Steve suggection Private Function CreateLine(ByVal grossAmount As Integer, ByVal LineNumber As String, ByVal Quantity As Integer, ByVal UOM As String) As ILineInfo Try Dim Line As LineInfo Dim inv As InvoiceItem Line = New LineInfo inv = New InvoiceItem Line.GrossAmount = Convert.ToString(grossAmount) 'Line.GrossAmount = Convert.ToString(inv.extended_price) try to pull from invoice item Line.LineNumber = LineNumber 'Line.LineNumber = inv.line_number Line.Quantity = Quantity 'Line.Quantity = inv.quantity Line.UnitOfMeasure = UOM 'Line.UnitOfMeasure = inv.UOM Return Line Catch ex As Exception Return ex End Try End Function _ Public Function InvoiceParseTest(ByVal input As String) As String Dim inv As InvoiceItem Try inv = New InvoiceItem inv.parse(input) Return inv.getValues Catch ex As Exception Return ex.Message End Try End Function _ Public Function BDInvoiceParseTest(ByVal input As String) As String Dim inv As InvoiceItem Try inv = New InvoiceItem inv.BDparse(input) Return inv.getValues Catch ex As Exception Return ex.Message End Try End Function _ Public Function LogTest(ByVal input As String) As String Try WriteLog(input) Return True Catch ex As Exception Return ex.Message End Try End Function Private Sub WriteLog(ByVal input As String) Dim remoteIP As String Dim fn As String Dim sw As StreamWriter Try If ConfigurationManager.AppSettings("LogEvents") = False Then Exit Sub remoteIP = HttpContext.Current.Request.ServerVariables.Item("REMOTE_ADDR") input = Now & "|" & remoteIP & "|" & input fn = Server.MapPath("logs") & "\" & Now.ToString("yyyyMMdd") & ".txt" sw = New StreamWriter(fn, True) sw.WriteLine(input) sw.Close() Catch ex As Exception Throw New Exception(ex.Message) End Try End Sub Private Structure InvoiceItem Dim company As String Dim division As String Dim customer As String Dim exempt_yn As String Dim certificate As String Dim invoice_date As String Dim store_code As String Dim open_header As String Dim order_number As String Dim line_number As String Dim sold_county As String Dim sold_city As String Dim sold_in_city As String Dim sold_state As String Dim sold_zip As String Dim sold_country As String Dim to_county As String Dim to_city As String Dim to_in_city As String Dim to_state As String Dim to_zip As String Dim to_country As String Dim from_county As String Dim from_city As String Dim from_in_city As String Dim from_state As String Dim from_zip As String Dim from_country As String Dim item As String Dim product_code As String Dim type As String Dim tax_yn As String Dim item_type As String Dim open_detail As String Dim extended_price As String Dim quantity As String Dim write_to_database As String Dim UOM As String 'Added by Kimmy Wang 12/11/2015 as it is a required filed Public Sub parse(ByVal input As String) company = input.Substring(0, 3).Trim division = input.Substring(3, 2).Trim customer = input.Substring(3, 9).Trim exempt_yn = input.Substring(12, 1).Trim certificate = input.Substring(13, 15).Trim invoice_date = input.Substring(502, 10).Trim store_code = input.Substring(36, 10).Trim open_header = input.Substring(46, 6).Trim order_number = input.Substring(52, 7).Trim line_number = input.Substring(59, 3).Trim sold_county = input.Substring(62, 35).Trim 'if(sold_county[0]==' ') strcpy(sold_county,NULL) sold_city = input.Substring(97, 35).Trim ' sold_city+20," ",15) sold_in_city = input.Substring(132, 1).Trim sold_state = input.Substring(133, 2).Trim sold_zip = input.Substring(135, 9).Trim sold_country = input.Substring(144, 35).Trim to_county = input.Substring(179, 35).Trim 'if(to_county[0]==' ') strcpy(to_county,NULL) to_city = input.Substring(214, 35).Trim ' to_city+20," ",15) to_in_city = input.Substring(249, 1).Trim to_state = input.Substring(250, 2).Trim to_zip = input.Substring(252, 9).Trim to_country = input.Substring(261, 35).Trim from_county = input.Substring(296, 35).Trim 'if(from_county[0]==' ') strcpy(from_county,NULL) from_city = input.Substring(331, 35).Trim ' from_city+20," ",15) from_in_city = input.Substring(366, 1).Trim from_state = input.Substring(367, 2).Trim from_zip = input.Substring(369, 9).Trim from_country = input.Substring(378, 35).Trim item = input.Substring(413, 20).Trim product_code = input.Substring(433, 5).Trim type = input.Substring(438, 1).Trim tax_yn = input.Substring(439, 1).Trim item_type = input.Substring(440, 1).Trim open_detail = input.Substring(441, 26).Trim extended_price = input.Substring(467, 17).Trim quantity = input.Substring(484, 17).Trim UOM = input.Substring(512, 2).Trim 'Added by Kimmy Wang as it is a required field now. 12/11/2015 write_to_database = input.Substring(501, 1).Trim End Sub Public Sub BDparse(ByVal input As String) 'For use by BirdDog, which we are not using Birddog now company = input.Substring(0, 3).Trim division = input.Substring(3, 2).Trim customer = input.Substring(3, 9).Trim exempt_yn = "N" certificate = "" invoice_date = "" store_code = "" open_header = "" order_number = input.Substring(12, 7).Trim line_number = input.Substring(19, 3).Trim sold_county = "" sold_city = input.Substring(22, 35).Trim sold_in_city = "Y" sold_state = input.Substring(57, 2).Trim sold_zip = input.Substring(59, 9).Trim sold_country = input.Substring(68, 35).Trim to_county = "" to_city = input.Substring(103, 35).Trim to_in_city = "Y" to_state = input.Substring(138, 2).Trim to_zip = input.Substring(140, 9).Trim to_country = input.Substring(149, 35).Trim from_county = "" from_city = input.Substring(184, 35).Trim from_in_city = "Y" from_state = input.Substring(219, 2).Trim from_zip = input.Substring(221, 9).Trim from_country = input.Substring(230, 35).Trim item = input.Substring(265, 20).Trim product_code = input.Substring(285, 5).Trim type = "I" tax_yn = "Y" item_type = "0" open_detail = "" extended_price = input.Substring(290, 17).Trim quantity = input.Substring(307, 17).Trim write_to_database = "N" End Sub Public Function getValues() As String Dim str As String str = "company: " & company & vbCrLf str += "division: " & division & vbCrLf str += "customer: " & customer & vbCrLf str += "exempt_yn: " & exempt_yn & vbCrLf str += "certificate: " & certificate & vbCrLf str += "invoice_date: " & invoice_date & vbCrLf str += "store_code: " & store_code & vbCrLf str += "open_header: " & open_header & vbCrLf str += "order_number: " & order_number & vbCrLf str += "line_number: " & line_number & vbCrLf str += "sold_county: " & sold_county & vbCrLf str += "sold_city: " & sold_city & vbCrLf str += "sold_in_city: " & sold_in_city & vbCrLf str += "sold_state: " & sold_state & vbCrLf str += "sold_zip: " & sold_zip & vbCrLf str += "sold_country: " & sold_country & vbCrLf str += "to_county: " & to_county & vbCrLf str += "to_city: " & to_city & vbCrLf str += "to_in_city: " & to_in_city & vbCrLf str += "to_state: " & to_state & vbCrLf str += "to_zip: " & to_zip & vbCrLf str += "to_country: " & to_country & vbCrLf str += "from_county: " & from_county & vbCrLf str += "from_city: " & from_city & vbCrLf str += "from_in_city: " & from_in_city & vbCrLf str += "from_state: " & from_state & vbCrLf str += "from_zip: " & from_zip & vbCrLf str += "from_country: " & from_country & vbCrLf str += "item: " & item & vbCrLf str += "product_code: " & product_code & vbCrLf str += "type: " & type & vbCrLf str += "tax_yn: " & tax_yn & vbCrLf str += "item_type: " & item_type & vbCrLf str += "open_detail: " & open_detail & vbCrLf str += "extended_price: " & extended_price & vbCrLf str += "quantity: " & quantity & vbCrLf str += "write_to_database:" & write_to_database & vbCrLf str += "UOM: " & UOM & vbCrLf 'Added by Kimmy Wang 12/11/2015 as it is required now Return str End Function End Structure Private Structure Address Dim address1 As String Dim address2 As String Dim address3 As String Dim county As String Dim city As String Dim state As String Dim zip As String Public Sub parse(ByVal input As String) Dim tmp() As String tmp = input.Split("|") If tmp.Length > 0 Then county = tmp(0) Else county = "" If tmp.Length > 1 Then city = tmp(1) Else city = "" If tmp.Length > 2 Then state = tmp(2) Else state = "" If tmp.Length > 3 Then zip = tmp(3) Else zip = "" If tmp.Length > 4 Then address1 = tmp(4) Else address1 = "" If tmp.Length > 5 Then address2 = tmp(5) Else address2 = "" If tmp.Length > 6 Then address3 = tmp(6) Else address3 = "" End Sub Public Function getValues() As String Dim str As String str = "county: " & county & vbCrLf str += "city: " & city & vbCrLf str += "state: " & state & vbCrLf str += "zip: " & zip & vbCrLf str += "address1: " & address1 & vbCrLf str += "address2: " & address2 & vbCrLf str += "address3: " & address3 & vbCrLf Return str End Function End Structure Private Structure CompanyInfo Dim Company As String Dim ExternalCompanyId As String Dim UserName As String Dim Password As String Public Sub Load(ByVal CompanyCode As String) Dim str As String Dim tmp() As String str = ConfigurationManager.AppSettings(CompanyCode) If str = Nothing Then str = ConfigurationManager.AppSettings(ConfigurationManager.AppSettings("DefaultCompanyCode")) End If tmp = str.Split("|") If tmp.Length = 0 Then Throw New Exception("Invalid Config.") Company = tmp(0) ExternalCompanyId = tmp(1) UserName = tmp(2) Password = tmp(3) End Sub End Structure End Class