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 static void Main() { try { string summary; #region Report Tax CustomerOrder order = new CustomerOrder(); order.AddressLine1 = "631 LUPINE DR"; order.City = "FORT COLLINS"; order.Country = "US"; order.State = "CO"; order.PostalCode = "80524"; order.InProduction = false; order.IsCommit = false; order.OCN = "041025304MS"; order.Quantity = 1; order.TotalAmount = 66.98m; order.TotalTax = 4.96m; GetTaxResult getTaxResult = GetTax.Execute(order, out summary); PostTaxResult postTaxResult = PostTax.Execute(order, getTaxResult, out summary); #endregion #region same day cancellation or when shipment charges is filed CustomerOrder cancel = new CustomerOrder(); cancel.InProduction = false; cancel.OCN = "041025304MS"; CancelTaxResult cancelTaxResult = CancelTax.Execute(cancel.InProduction, cancel.OCN, out summary); #endregion #region harware refund CustomerOrder refund = new CustomerOrder(); refund.AddressLine1 = "631 LUPINE DR"; refund.City = "FORT COLLINS"; refund.Country = "US"; refund.State = "CO"; refund.PostalCode = "80524"; refund.InProduction = false; refund.IsCommit = false; refund.OCN = "041025304MS"; refund.Quantity = 1; refund.TotalAmount = 54.99m; // hardware cost refund.TotalTax = 4.06m; // tax portion of hardware cost AdjustTaxResult adjustTaxResult = AdjustTaxTest.Execute(refund, out summary); #endregion } catch (Exception ex) { Console.WriteLine("An Exception Occured: " + ex.Message); } finally { Console.WriteLine("Done"); Console.ReadLine(); } }
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 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); } }