Example #1
0
        public ITaxProviderResult CancelTax(string companyCode, string docCode, DocumentType docType)
        {
            var result = new AvaTaxResult();

            var ctr = new CancelTaxRequest
            {
                CompanyCode = companyCode,
                DocCode     = docCode,
                DocType     = ConvertDocType(docType),
                CancelCode  = CancelCode.DocDeleted
            };

            var svc = GetTaxServiceProxy();

            var ctres = svc.CancelTax(ctr);


            if (ctres.ResultCode != avt.SeverityLevel.Success)
            {
                result.Success = false;
                result.Messages.Add("CancelTax Failed");
                ApplyMessagesToResult(result, ctres.Messages);
            }
            else
            {
                result.Success = true;
            }

            return(result);
        }
Example #2
0
 private static void ApplyMessagesToResult(AvaTaxResult result, avt.Messages messages)
 {
     if (messages != null)
     {
         foreach (avt.Message item in messages)
         {
             result.Messages.Add(item.Name + Environment.NewLine + item.Summary + Environment.NewLine +
                                 item.Details);
         }
     }
 }
Example #3
0
        public ITaxProviderResult TestConnection()
        {
            var result = new AvaTaxResult();

            var svc = GetTaxServiceProxy();

            var pingResult = svc.Ping("Test Connection Message at " + DateTime.Now);

            if (pingResult.ResultCode == avt.SeverityLevel.Success)
            {
                result.Success = true;
            }
            else
            {
                result.Success = false;
                ApplyMessagesToResult(result, pingResult.Messages);
            }

            return(result);
        }
Example #4
0
        public ITaxProviderResult PostTax(string companyCode,
                                          string docCode,
                                          DocumentType docType,
                                          decimal totalAmount,
                                          decimal totalTax)
        {
            var result = new AvaTaxResult();

            var ptr = new PostTaxRequest();

            ptr.CompanyCode = companyCode;
            ptr.DocCode     = docCode;
            ptr.DocType     = ConvertDocType(docType);
            ptr.DocDate     = DateTime.UtcNow;
            ptr.TotalAmount = totalAmount;
            ptr.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);
        }
Example #5
0
        public ITaxProviderResult GetTax(DocumentType docType, string companyCode, string docCode,
                                         BaseAddress originationAddress, BaseAddress destinationAddress, List <Line> items, decimal orderDiscount,
                                         string customerCode, string currencyCode,
                                         bool taxExempt, string taxExemptionNumber, bool applyVATRules)
        {
            var result = new AvaTaxResult();

            var gtr = new GetTaxRequest();

            gtr.OriginAddress      = ConvertBaseAddress(originationAddress);
            gtr.DestinationAddress = ConvertBaseAddress(destinationAddress);

            gtr.CurrencyCode = currencyCode;

            if (taxExempt)
            {
                if (!applyVATRules)
                {
                    gtr.ExemptionNo = taxExemptionNumber;
                }
                else
                {
                    gtr.BusinessIdentificationNo = taxExemptionNumber;
                }
            }

            gtr.CompanyCode  = companyCode;
            gtr.CustomerCode = customerCode;
            gtr.DetailLevel  = DetailLevel.Line;
            gtr.DocCode      = docCode;
            gtr.DocType      = ConvertDocType(docType);
            gtr.DocDate      = DateTime.UtcNow;

            gtr.Discount = -1 * orderDiscount;
            foreach (var l in items)
            {
                var nl = ConvertLine(l);
                gtr.Lines.Add(nl);
            }

            var svc   = GetTaxServiceProxy();
            var gtres = svc.GetTax(gtr);


            if (gtres.ResultCode != avt.SeverityLevel.Success)
            {
                result.Success = false;
                result.Messages.Add("GetTax Failed");
                ApplyMessagesToResult(result, gtres.Messages);
            }
            else
            {
                result.Success = true;

                result.DocCode     = gtres.DocCode;
                result.TotalAmount = gtres.TotalAmount;
                result.TotalTax    = gtres.TotalTax;

                // shipping line is always present ( even if 0 )
                // so the last item is shipping
                for (var i = 0; i < gtres.TaxLines.Count; i++)
                {
                    var line = gtres.TaxLines[i];
                    if (i < gtres.TaxLines.Count - 1)
                    {
                        var lineResult = new AvaTaxLineResult();
                        lineResult.No       = line.No;
                        lineResult.TaxRate  = (decimal)line.Rate;
                        lineResult.TaxValue = line.Tax;
                        result.Items.Add(lineResult);
                    }
                    else
                    {
                        result.ShippingTax     = line.Tax;
                        result.ShippingTaxRate = (decimal)line.Rate;
                    }
                }
                result.ItemsTax = result.TotalTax - result.ShippingTax;
            }

            return(result);
        }