Пример #1
0
        public static AvaTaxResult GetTax(string URL, DocumentType DocType,
                                            string Account, string License,
                                            string CompanyCode, string UserName, string Password,
                                            string OrderIdentifier, BaseAddress OriginationAddress,
                                            BaseAddress DestinationAddress, List<Line> items,
                                            string CustomerCode)
        {

            BVSoftware.Avalara.AvaTaxResult result = new AvaTaxResult();

            avt.TaxService.GetTaxRequest gtr = new avt.TaxService.GetTaxRequest();
            gtr.OriginAddress = ConvertBaseAddress(OriginationAddress);
            gtr.DestinationAddress = ConvertBaseAddress(DestinationAddress);
            
            
            //' Origin and Destination addresses
            //OriginationAddress.AddressCode = "O"
            //DestinationAddress.AddressCode = "D"
            //gtr.Addresses = New BaseAddress(2) {}
            //gtr.Addresses(0) = OriginationAddress
            //gtr.Addresses(1) = DestinationAddress
            //Document Level Origin and Destination Addresses - see AddressCode field.
            //gtr.OriginCode = gtr.Addresses(0).AddressCode
            //gtr.DestinationCode = gtr.Addresses(1).AddressCode

            gtr.CompanyCode = CompanyCode;
            gtr.CustomerCode = CustomerCode;
            gtr.DetailLevel = avt.TaxService.DetailLevel.Document;
            gtr.DocCode = OrderIdentifier;
            gtr.DocType = ConvertDocType(DocType);
            gtr.DocDate = DateTime.Now;
            
            foreach (Line l in items)
            {
                avt.TaxService.Line nl = ConvertLine(l);
                gtr.Lines.Add(nl);
            }            
            
            avt.TaxService.TaxSvc svc = GetTaxServiceProxy(URL, Account, License, UserName, Password);
            avt.TaxService.GetTaxResult 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.DocId = gtres.DocId;
            result.TotalAmount = gtres.TotalAmount;
            result.TotalTax = gtres.TotalTax;

            return result;                      
        }
Пример #2
0
        public static AvaTaxResult PostTax(string URL, string Account,
                                             string License,
                                            string CompanyCode, string UserName, string Password,
                                            string OrderIdentifier, string DocId,
                                            DocumentType DocType, decimal TotalAmount,
                                            decimal TotalTax)
        {

            BVSoftware.Avalara.AvaTaxResult result = new AvaTaxResult();

            avt.TaxService.PostTaxRequest ptr = new avt.TaxService.PostTaxRequest();
            ptr.CompanyCode = CompanyCode;
            ptr.DocId = DocId;
            ptr.DocType = ConvertDocType(DocType);
            ptr.DocDate = DateTime.Now;
            ptr.TotalAmount = TotalAmount;
            ptr.TotalTax = TotalTax;

            avt.TaxService.TaxSvc svc = GetTaxServiceProxy(URL, Account, License, UserName, Password);

            avt.TaxService.PostTaxResult 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.DocId = DocId;
            result.TotalAmount = TotalAmount;
            result.TotalTax = TotalTax;

            return result;
        }
Пример #3
0
 public static void GetAvalaraTaxes(Orders.Order order, 
                                 string identifier, 
                                 BaseAddress origin, 
                                 BaseAddress destination,List<Line> lines, 
                                 string customerCode, MerchantTribeApplication app)
 {
     var result = new AvaTaxResult();            
         result = BVAvaTax.GetTax(app.CurrentStore.Settings.Avalara.ServiceUrl, 
             DocumentType.SalesOrder, 
             app.CurrentStore.Settings.Avalara.Account, 
             app.CurrentStore.Settings.Avalara.LicenseKey, 
             app.CurrentStore.Settings.Avalara.CompanyCode,
             app.CurrentStore.Settings.Avalara.Username, 
             app.CurrentStore.Settings.Avalara.Password,
             identifier, origin, destination, lines, customerCode);
                 
     if (result != null)
     {
         if (result.Success == true)
         {                    
             order.TotalTax = result.TotalTax;
         }
         else
         {
             if (app.CurrentStore.Settings.Avalara.DebugMode)
             {
             string note = "Avalara - Get Tax Request Failed:";
             foreach(var m in result.Messages)
                  {
                      note += "\n" + m;
                  }                
             order.Notes.Add(new Orders.OrderNote() {
                  IsPublic = false,
                  Note = note});                         
             app.OrderServices.Orders.Update(order);
                                         
                EventLog.LogEvent("Avalara -  ApplyTaxes", note, Web.Logging.EventLogSeverity.Error);
             }
         }
     }
 }
Пример #4
0
 internal 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);
         }
     }
 }
Пример #5
0
        public static AvaTaxResult CancelTax(string URL, string Account,
                                            string License,
                                           string CompanyCode, string UserName, string Password,
                                           string OrderIdentifier, string DocId,
                                           DocumentType DocType)
        {
            BVSoftware.Avalara.AvaTaxResult result = new AvaTaxResult();

            avt.TaxService.CancelTaxRequest ctr = new avt.TaxService.CancelTaxRequest();
            ctr.CompanyCode = CompanyCode;
            ctr.DocId = DocId;
            ctr.DocType = ConvertDocType(DocType);
            ctr.CancelCode = avt.TaxService.CancelCode.DocDeleted;

            avt.TaxService.TaxSvc svc = GetTaxServiceProxy(URL, Account, License, UserName, Password);

            avt.TaxService.CancelTaxResult 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;                                
        }