Exemple #1
0
        public AvaTaxResult 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);
        }
Exemple #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);
         }
     }
 }
Exemple #3
0
        public AvaTaxResult 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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        public AvaTaxResult 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
            {
                OriginAddress      = ConvertBaseAddress(originationAddress),
                DestinationAddress = ConvertBaseAddress(destinationAddress),
                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
                        {
                            No       = line.No,
                            TaxRate  = (decimal)line.Rate,
                            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);
        }