protected PostTaxRequest GetPostTaxRequestFromOrder(CustomerOrder customerOrder) { Decimal totalTax = customerOrderUtilities.GetTotalTax(customerOrder); PostTaxRequest postTaxRequest = new PostTaxRequest(); postTaxRequest.Commit = true; string companyCode = customSettings.TaxCalculatorAvalaraCompanyCode; postTaxRequest.CompanyCode = companyCode; string orderNumber = customerOrder.OrderNumber; postTaxRequest.DocCode = orderNumber; DateTime utcDateTime = customerOrder.OrderDate.UtcDateTime; postTaxRequest.DocDate = utcDateTime; postTaxRequest.DocType = DocumentType.SalesInvoice; string empty = string.Empty; postTaxRequest.NewDocCode = empty; Decimal num2 = NumberHelper.RoundCurrency(customerOrderUtilities.GetOrderTotal(customerOrder) - totalTax); postTaxRequest.TotalAmount = num2; Decimal num3 = totalTax; postTaxRequest.TotalTax = num3; return(postTaxRequest); }
public void PostTax(OriginAddress originAddress, CustomerOrder customerOrder) { if (!this.AvalaraSettings.PostTaxes) // Added condition to check post taxes setting { return; } string str = string.Empty; if (ValidateOrderAddressForAvalara(customerOrder)) { try { GetTaxRequest requestFromOrder1 = GetCalcTaxRequestFromOrder(originAddress, customerOrder, DocumentType.SalesInvoice); PostTaxRequest requestFromOrder2 = GetPostTaxRequestFromOrder(customerOrder); TaxSvc configuredTaxService = GetConfiguredTaxService(); configuredTaxService.GetTax(requestFromOrder1); str = this.ProcessAvalaraResponseMessage(configuredTaxService.PostTax(requestFromOrder2)); } catch (Exception ex) { LogHelper.For(this).Error("Error running Avalara PostTax method: " + ex.Message, "TaxCalculator_Avalara"); throw; } } else { LogHelper.For(this).Debug("The billto/shipto customer does not have an address specified. In order to calculate tax this must be set up.", "TaxCalculator_Avalara"); return; } if (string.IsNullOrEmpty(str)) { return; } LogHelper.For(this).Debug(str, "Avalara Result, PostTax: "); }
public static PostTaxResult Execute(CustomerOrder order, Avalara.AvaTax.Adapter.TaxService.GetTaxResult getTaxResult, out string summary) { summary = ""; TaxServiceWrapper taxSvcWrapper = new TaxServiceWrapper(); TaxSvc taxSvc = taxSvcWrapper.GetTaxSvcInstance(order.InProduction); PostTaxRequest postTaxRequest = new PostTaxRequest(); // Required Request Parameters postTaxRequest.CompanyCode = Properties.Settings.Default.CompanyCode; postTaxRequest.DocType = DocumentType.SalesInvoice; postTaxRequest.DocCode = getTaxResult.DocCode; postTaxRequest.Commit = order.IsCommit; postTaxRequest.DocDate = getTaxResult.DocDate; postTaxRequest.TotalTax = order.TotalTax; postTaxRequest.TotalAmount = order.TotalAmount; // Optional Request Parameters postTaxRequest.NewDocCode = order.OCN; PostTaxResult postTaxResult = taxSvc.PostTax(postTaxRequest); if (!postTaxResult.ResultCode.Equals(SeverityLevel.Success)) { foreach (Message message in postTaxResult.Messages) { summary = message.Summary; } } return(postTaxResult); }
public PostTaxResult PostTax(PostTaxRequest request) { _logger.Info("StubTaxProvider - PostTax"); return(new PostTaxResult() { IsSuccess = true }); }
public PostTaxResult PostTax(PostTaxRequest request) { var json = JsonConvert.SerializeObject(request); _logger.Info($"PostTax - {json}"); var provider = ExternalReportingProvider(); return(provider.PostTax(request)); }
public static void Test() { string accountNumber = ConfigurationManager.AppSettings["AvaTax:AccountNumber"]; string licenseKey = ConfigurationManager.AppSettings["AvaTax:LicenseKey"]; string serviceURL = ConfigurationManager.AppSettings["AvaTax:ServiceUrl"]; TaxSvc taxSvc = new TaxSvc(); // Header Level Parameters // Required Header Parameters taxSvc.Configuration.Security.Account = accountNumber; taxSvc.Configuration.Security.License = licenseKey; taxSvc.Configuration.Url = serviceURL; taxSvc.Configuration.ViaUrl = serviceURL; taxSvc.Profile.Client = "AvaTaxSample"; // Optional Header Parameters taxSvc.Profile.Name = "Development"; PostTaxRequest postTaxRequest = new PostTaxRequest(); // Required Request Parameters postTaxRequest.CompanyCode = "APITrialCompany"; postTaxRequest.DocType = DocumentType.SalesInvoice; postTaxRequest.DocCode = "INV001"; postTaxRequest.Commit = false; postTaxRequest.DocDate = DateTime.Parse("2014-01-01"); postTaxRequest.TotalTax = (decimal)14.27; postTaxRequest.TotalAmount = 175; // Optional Request Parameters postTaxRequest.NewDocCode = "INV001-1"; PostTaxResult postTaxResult = taxSvc.PostTax(postTaxRequest); Console.WriteLine("PostTaxTest Result: " + postTaxResult.ResultCode.ToString()); if (!postTaxResult.ResultCode.Equals(SeverityLevel.Success)) { foreach (Message message in postTaxResult.Messages) { Console.WriteLine(message.Summary); } } }
public static GetTaxResult Execute(CustomerOrder order, out string summary) { summary = ""; TaxServiceWrapper taxSvcWrapper = new TaxServiceWrapper(); TaxSvc taxSvc = taxSvcWrapper.GetTaxSvcInstance(order.InProduction); PostTaxRequest postTaxRequest = new PostTaxRequest(); GetTaxRequest getTaxRequest = BuildGetTaxRequest(order); GetTaxResult getTaxResult = taxSvc.GetTax(getTaxRequest); if (!getTaxResult.ResultCode.Equals(SeverityLevel.Success)) { foreach (Message message in getTaxResult.Messages) { summary = message.Summary; } } return(getTaxResult); }
public AvaTaxResult PostTax(string companyCode, string docCode, DocumentType docType, decimal totalAmount, decimal totalTax) { var result = new AvaTaxResult(); var ptr = new PostTaxRequest { CompanyCode = companyCode, DocCode = docCode, DocType = ConvertDocType(docType), DocDate = DateTime.UtcNow, TotalAmount = totalAmount, TotalTax = totalTax }; var svc = GetTaxServiceProxy(); var ptres = svc.PostTax(ptr); if (ptres.ResultCode != avt.SeverityLevel.Success) { result.Success = false; result.Messages.Add("PostTax Failed"); ApplyMessagesToResult(result, ptres.Messages); } else { result.Success = true; } result.DocCode = docCode; result.TotalAmount = totalAmount; result.TotalTax = totalTax; return(result); }
public void CommitTax(Order order) { if (!Enabled) { throw new InvalidOperationException("AvalaraInactiveException"); } // Avalara rounds each line item to two decimal places before calculating // the order total in GetTax(). The order total derived here may end up // with a different value, as we will only round the total. If the value // is different, it will generate a warning below, which we will ignore. decimal totalAmount = Decimal.Round(order.SubTotal(true) + order.ShippingTotal(true), 2, MidpointRounding.AwayFromZero); PostTaxRequest postTaxRequest = new PostTaxRequest { CompanyCode = CompanyCode, DocType = DocumentType.SalesInvoice, DocCode = order.OrderNumber.ToString(), DocDate = DateTime.Now, TotalAmount = totalAmount, TotalTax = order.TaxTotal(true), Commit = CommitTaxes, }; TaxSvc taxService = CreateTaxService(); PostTaxResult postTaxResult = taxService.PostTax(postTaxRequest); foreach (Message message in postTaxResult.Messages) { // Ignore warnings at this stage only if (message.Severity == SeverityLevel.Warning) { continue; } LogErrorMessage(message); } }
public PostTaxResult PostTax(PostTaxRequest request) { if (!IsActive) { return(new PostTaxResult() { IsSuccess = false, Messages = new[] { Messages.ServiceIsNotActive } }); } else { if (WriteTrace) { PXTrace.WriteInformation("PostTax Request: " + JsonConvert.SerializeObject(request, Formatting.Indented)); } return(new PostTaxResult() { IsSuccess = true, Messages = new string[0] }); } }
public override CAAdj CalculateExternalTax(CAAdj invoice) { var toAddress = GetToAddress(invoice); bool isNonTaxable = IsNonTaxable(toAddress); if (isNonTaxable) { ApplyTax(invoice, GetTaxResult.Empty); invoice.IsTaxValid = true; invoice.NonTaxable = true; invoice = Base.CAAdjRecords.Update(invoice); SkipTaxCalcAndSave(); return(invoice); } else if (invoice.NonTaxable == true) { Base.CurrentDocument.SetValueExt <CAAdj.nonTaxable>(invoice, false); } var service = TaxProviderFactory(Base, invoice.TaxZoneID); GetTaxRequest getRequest = BuildGetTaxRequest(invoice); if (getRequest.CartItems.Count == 0) { invoice.IsTaxValid = true; invoice.IsTaxSaved = false; invoice = Base.CAAdjRecords.Update(invoice); SkipTaxCalcAndSave(); } GetTaxResult result = service.GetTax(getRequest); if (result.IsSuccess) { try { ApplyTax(invoice, result); SkipTaxCalcAndSave(); } catch (PXOuterException ex) { try { CancelTax(invoice, VoidReasonCode.Unspecified); } catch (Exception) { throw new PXException(new PXException(ex, TX.Messages.FailedToApplyTaxes), TX.Messages.FailedToCancelTaxes); } string msg = TX.Messages.FailedToApplyTaxes; foreach (string err in ex.InnerMessages) { msg += Environment.NewLine + err; } throw new PXException(ex, msg); } catch (Exception ex) { try { CancelTax(invoice, VoidReasonCode.Unspecified); } catch (Exception) { throw new PXException(new PXException(ex, TX.Messages.FailedToApplyTaxes), TX.Messages.FailedToCancelTaxes); } string msg = TX.Messages.FailedToApplyTaxes; msg += Environment.NewLine + ex.Message; throw new PXException(ex, msg); } PostTaxRequest request = new PostTaxRequest(); request.CompanyCode = getRequest.CompanyCode; request.DocCode = getRequest.DocCode; request.DocDate = getRequest.DocDate; request.DocType = getRequest.DocType; request.TotalAmount = result.TotalAmount; request.TotalTaxAmount = result.TotalTaxAmount; PostTaxResult postResult = service.PostTax(request); if (postResult.IsSuccess) { invoice.IsTaxValid = true; invoice = Base.CAAdjRecords.Update(invoice); SkipTaxCalcAndSave(); } } else { LogMessages(result); throw new PXException(TX.Messages.FailedToGetTaxes); } return(invoice); }
private void buttonPostTax_Click(object sender, System.EventArgs e) { try { if (!Util.IsValidDateTime(textDocDate.Text)) { MessageBox.Show("Invalid date/time value.", "Invalid Field", MessageBoxButtons.OK, MessageBoxIcon.Error); textDocDate.Focus(); return; } if (!Util.CheckRequiredField(textTotalAmount, "Total Price")) { return; } if (!Util.CheckRequiredField(textTotalTax, "Total Tax")) { return; } //########################################################################### //### 1st WE CREATE THE REQUEST OBJECT FOR DOCUMENT THAT SHOULD BE POSTED ### //########################################################################### PostTaxRequest postTaxRequest = new PostTaxRequest(); //########################################################### //### 2nd WE LOAD THE REQUEST-LEVEL DATA INTO THE REQUEST ### //########################################################### postTaxRequest.CompanyCode = textCompanyCode.Text; postTaxRequest.DocType = (DocumentType)comboDocType.SelectedItem; postTaxRequest.DocCode = textDocCode.Text; postTaxRequest.DocDate = Convert.ToDateTime(textDocDate.Text); postTaxRequest.TotalAmount = Convert.ToDecimal(textTotalAmount.Text); postTaxRequest.TotalTax = Convert.ToDecimal(textTotalTax.Text); postTaxRequest.NewDocCode = textNewDocCode.Text; postTaxRequest.Commit = chkCommit.Checked; //############################################################################################ //### 3rd WE INVOKE THE POSTTAX() 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 _postTaxResult = taxSvc.PostTax(postTaxRequest); Util.PostMethodCall(this, lblStatus); //##################################### //### 4th WE READ THE RESULT OBJECT ### //##################################### lblResultCode.Text = _postTaxResult.ResultCode.ToString(); Util.SetMessageLabelText(lblResultMsg, _postTaxResult); postTaxRequest = null; taxSvc = null; } catch (Exception ex) { Util.ShowError(ex); } finally { Util.PostMethodCall(this, lblStatus); } }