public static void SetupService(PXGraph graph, BaseSvc service) { TXAvalaraSetup avalaraSetup = PXSelect <TXAvalaraSetup> .Select(graph); if (avalaraSetup != null) { if (avalaraSetup.IsActive != true) { throw new PXSetPropertyException(Messages.AvalaraIsNotActive); } if (avalaraSetup.Url == null) { throw new PXSetPropertyException(Messages.AvalaraUrlIsMissing, avalaraSetup.Url); } service.Configuration.Url = avalaraSetup.Url; service.Configuration.Security.Account = avalaraSetup.Account; service.Configuration.Security.License = avalaraSetup.Licence; service.Configuration.RequestTimeout = avalaraSetup.Timeout.GetValueOrDefault(30); service.Profile.Client = "Acumatica,4.0.0.0"; service.Configuration.LogTransactions = false; service.Configuration.LogSoap = false; service.Configuration.LogMessages = false; service.Configuration.LogLevel = LogLevel.NONE; } }
public static string CompanyCodeFromBranch(PXGraph graph, int?branchID) { TXAvalaraMapping m = PXSelect <TXAvalaraMapping, Where <TXAvalaraMapping.branchID, Equal <Required <TXAvalaraMapping.branchID> > > > .Select(graph, branchID); if (m == null) { TXAvalaraSetup avalaraSetup = PXSelect <TXAvalaraSetup> .Select(graph); if (avalaraSetup == null) { throw new PXSetPropertyException(Messages.AvalaraIsNotActive); } throw new PXException(Messages.AvalaraBranchToCompanyCodeMappingIsMissing); } return(m.CompanyCode); }
public void Post(Document doc) { TXAvalaraSetup avalaraSetup = PXSelect <TXAvalaraSetup> .Select(this); if (avalaraSetup == null) { throw new PXException(Messages.AvalaraSetupNotConfigured); } CommitTaxRequest request = new CommitTaxRequest(); request.CompanyCode = AvalaraMaint.CompanyCodeFromBranch(this, doc.BranchID); request.DocCode = string.Format("{0}.{1}.{2}", doc.Module, doc.DocType, doc.RefNbr); if (doc.Module == "AP") { if (doc.DocType == AP.APDocType.Refund) { request.DocType = DocumentType.ReturnInvoice; } else { request.DocType = DocumentType.PurchaseInvoice; } } else if (doc.Module == "AR") { if (doc.DocType == AR.ARDocType.CreditMemo) { request.DocType = DocumentType.ReturnInvoice; } else { request.DocType = DocumentType.SalesInvoice; } } else if (doc.Module == "CA") { if (doc.DrCr == CA.CADrCr.CADebit) { request.DocType = DocumentType.SalesInvoice; } else { request.DocType = DocumentType.PurchaseInvoice; } } else { throw new PXException(PXMessages.LocalizeFormatNoPrefixNLA(Messages.InvalidModule, doc.Module)); } CommitTaxResult result = service.CommitTax(request); bool setPosted = false; if (result.ResultCode == SeverityLevel.Success) { setPosted = true; } else { //Avalara retuned an error - The given document is already marked as posted on the avalara side. //Just fix the discrepency by setting the IsTaxPosted=1 in the acumatica document. Do not return this as an error to the user. if (result.ResultCode == SeverityLevel.Error && result.Messages.Count == 1 && result.Messages[0].Details == "Expected Posted") { setPosted = true; } } if (setPosted) { if (doc.Module == "AP") { PXDatabase.Update <AP.APRegister>( new PXDataFieldAssign("IsTaxPosted", true), new PXDataFieldRestrict("DocType", PXDbType.Char, 3, doc.DocType, PXComp.EQ), new PXDataFieldRestrict("RefNbr", PXDbType.NVarChar, 15, doc.RefNbr, PXComp.EQ) ); } else if (doc.Module == "AR") { PXDatabase.Update <AR.ARRegister>( new PXDataFieldAssign("IsTaxPosted", true), new PXDataFieldRestrict("DocType", PXDbType.Char, 3, doc.DocType, PXComp.EQ), new PXDataFieldRestrict("RefNbr", PXDbType.NVarChar, 15, doc.RefNbr, PXComp.EQ) ); } else if (doc.Module == "CA") { PXDatabase.Update <CA.CAAdj>( new PXDataFieldAssign("IsTaxPosted", true), new PXDataFieldRestrict("AdjRefNbr", PXDbType.NVarChar, 15, doc.RefNbr, PXComp.EQ) ); } } else { StringBuilder sb = new StringBuilder(); foreach (Avalara.AvaTax.Adapter.Message msg in result.Messages) { sb.AppendLine(msg.Name + ": " + msg.Details); } throw new PXException(sb.ToString()); } }