public static CommitTaxResult Execute(bool inProduction, string strOCN, out string summary) { summary = ""; TaxServiceWrapper taxSvcWrapper = new TaxServiceWrapper(); TaxSvc taxSvc = taxSvcWrapper.GetTaxSvcInstance(inProduction); CommitTaxRequest commitTaxRequest = new CommitTaxRequest(); // Required Parameters commitTaxRequest.DocCode = strOCN; commitTaxRequest.DocType = DocumentType.SalesInvoice; commitTaxRequest.CompanyCode = Properties.Settings.Default.CompanyCode; // Optional Parameters //commitTaxRequest.NewDocCode = "INV001"; CommitTaxResult commitTaxResult = taxSvc.CommitTax(commitTaxRequest); if (!commitTaxResult.ResultCode.Equals(SeverityLevel.Success)) { foreach (Message message in commitTaxResult.Messages) { summary = message.Summary; } } return(commitTaxResult); }
public virtual ARInvoice CommitExternalTax(ARInvoice doc) { if (doc != null && doc.IsTaxValid == true && doc.NonTaxable == false && IsExternalTax(doc.TaxZoneID) && doc.InstallmentNbr == null) { if (TaxPluginMaint.IsActive(Base, doc.TaxZoneID)) { var service = ExternalTax.TaxProviderFactory(Base, doc.TaxZoneID); CommitTaxRequest request = new CommitTaxRequest(); request.CompanyCode = ExternalTax.CompanyCodeFromBranch(Base, doc.TaxZoneID, doc.BranchID); request.DocCode = string.Format("AR.{0}.{1}", doc.DocType, doc.RefNbr); if (doc.DocType == ARDocType.CreditMemo) { request.DocType = TaxDocumentType.ReturnInvoice; } else { request.DocType = TaxDocumentType.SalesInvoice; } CommitTaxResult result = service.CommitTax(request); if (result.IsSuccess) { doc.IsTaxPosted = true; } else { //Avalara retuned an error - The given document is already marked as posted on the avalara side. if (!result.IsSuccess && result.Messages.Any(t => t.Contains("Expected Posted"))) { //ignore this error - everything is cool } else { //show as warning. StringBuilder sb = new StringBuilder(); foreach (var msg in result.Messages) { sb.AppendLine(msg); } if (sb.Length > 0) { doc.WarningMessage = PXMessages.LocalizeFormatNoPrefixNLA(Messages.PostingToExternalTaxProviderFailed, sb.ToString()); } } } } } return(doc); }
private void buttonCommitTax_Click(object sender, EventArgs e) { try { //############################################################################## //### 1st WE CREATE THE REQUEST OBJECT FOR DOCUMENT THAT SHOULD BE COMMITTED ### //############################################################################## CommitTaxRequest commitTaxRequest = new CommitTaxRequest(); //########################################################### //### 2nd WE LOAD THE REQUEST-LEVEL DATA INTO THE REQUEST ### //########################################################### commitTaxRequest.CompanyCode = textCompanyCode.Text; commitTaxRequest.DocType = (DocumentType)comboDocType.SelectedItem; commitTaxRequest.DocCode = textDocCode.Text; commitTaxRequest.NewDocCode = textNewDocCode.Text; //############################################################################################## //### 3rd WE INVOKE THE COMMITTAX() METHOD OF THE TAXSVC OBJECT AND GET BACK A RESULT OBJECT ### //############################################################################################## Util.PreMethodCall(this, lblStatus); TaxSvc taxSvc = new TaxSvc(); ((formMain)this.Owner).SetConfig(taxSvc); //set the Url and Security configuration _commitTaxResult = taxSvc.CommitTax(commitTaxRequest); Util.PostMethodCall(this, lblStatus); //##################################### //### 4th WE READ THE RESULT OBJECT ### //##################################### lblResultCode.Text = _commitTaxResult.ResultCode.ToString(); Util.SetMessageLabelText(lblResultMsg, _commitTaxResult); commitTaxRequest = null; taxSvc = null; } catch (Exception ex) { Util.ShowError(ex); } finally { Util.PostMethodCall(this, lblStatus); } }
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()); } }
public void Post(Document doc) { if (!TaxPluginMaint.IsActive(this, doc.TaxZoneID)) { throw new PXException(Messages.ExternalTaxProviderNotConfigured); } var service = TaxProviderFactory(this, doc.TaxZoneID); var request = new CommitTaxRequest(); request.CompanyCode = ExternalTax.CompanyCodeFromBranch(this, doc.TaxZoneID, doc.BranchID); request.DocCode = string.Format("{0}.{1}.{2}", doc.Module, doc.DocType, doc.RefNbr); request.DocType = GetTaxDocumentType(doc); CommitTaxResult result = service.CommitTax(request); bool setPosted = false; if (result.IsSuccess) { 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.IsSuccess && result.Messages.Any(t => t.Contains("Expected Posted"))) { setPosted = true; } } if (setPosted) { if (doc.Module == BatchModule.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 == BatchModule.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 == BatchModule.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 (var msg in result.Messages) { sb.AppendLine(msg); } throw new PXException(sb.ToString()); } }