コード例 #1
0
ファイル: BVAvaTax.cs プロジェクト: appliedi/MerchantTribe
        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
        protected decimal GetTax(Address shipToAddress, bool isInvoice, ref decimal taxableAmount, ref decimal taxAmount)
        {
            try
            {
                Avalara.AvaTax.Adapter.TaxService.GetTaxRequest getTaxrequest = new Avalara.AvaTax.Adapter.TaxService.GetTaxRequest();

                getTaxrequest.DocDate = DateTime.Now;

                if (isInvoice)
                {
                    getTaxrequest.DocType = Avalara.AvaTax.Adapter.TaxService.DocumentType.SalesInvoice;
                }
                else
                {
                    getTaxrequest.DocType = Avalara.AvaTax.Adapter.TaxService.DocumentType.SalesOrder;
                }
                getTaxrequest.DocCode = "1";

                Avalara.AvaTax.Adapter.AddressService.Address address;
                address = new Avalara.AvaTax.Adapter.AddressService.Address(); //Ship From
                address.Line1 = "11509 SW Herman Rd";
                address.Line2 = null;
                address.Line3 = null;
                address.City = "Tualatin";
                address.Region = "OR";
                address.PostalCode = "97062";
                address.Country = "US";

                getTaxrequest.OriginAddress = address;

                address = new Avalara.AvaTax.Adapter.AddressService.Address(); //Ship To
                address.Line1 = shipToAddress.Address1;
                address.Line2 = shipToAddress.Address2;
                address.City = shipToAddress.City;
                address.Region = shipToAddress.State;
                address.PostalCode = shipToAddress.Zip;
                address.Country = shipToAddress.Country;
                getTaxrequest.DestinationAddress = address;

                getTaxrequest.CustomerCode = shipToAddress.CompanyName;

                //first line is equal to the total and the other equal to the shipping + handling amount
                Avalara.AvaTax.Adapter.TaxService.Line line;
                line = new Avalara.AvaTax.Adapter.TaxService.Line();
                line.No = "01";                                    //What does this number refer to? Do we have to set it to something specific?
                //line number is a unique identifier for each line of the invoice, usually sequential (1000, 2000, 3000, or something like that)
                line.ItemCode = "P0000000";                     //I believe Lightspeed already entered the items and their codes into the Avatax    Dashboard. How do we retreive these programatically?                     //if lightspeed entered their items in the dashboard, you will still need to pass the item number to activate the mapping to the tax code.
                line.Qty = 1;
                line.Amount = decimal.Parse(EstimatedTotalLabel.Text);
                line.Discounted = false;

                //Not needed: line.ExemptionNo = "";
                //Not needed: line.Ref1 = "client specific reference string 1";   //optional //What are Ref1 and Ref2 used for? Do we have to set them to anything specific?
                //Not needed: line.Ref2 = "client specific reference #2";
                //Not needed: line.RevAcct = "a revenue account";                 //optional //Does this have to be an account number? If so, where do we get this number from?
                line.TaxCode = "AVATAX";                        //How do we get the Tax code? Is it specific to an item or just one general Tax code?
                //a tax code will only need to be passed if the item isn't mapped in the dashboard as you have indicated lightspeed has done
                getTaxrequest.Lines.Add(line);

                //first line is equal to the total and the other equal to the shipping + handling amount
                line = new Avalara.AvaTax.Adapter.TaxService.Line();
                line.No = "02";                                    //What does this number refer to? Do we have to set it to something specific?
                //line number is a unique identifier for each line of the invoice, usually sequential (1000, 2000, 3000, or something like that)
                line.ItemCode = "P0000000";                     //I believe Lightspeed already entered the items and their codes into the Avatax    Dashboard. How do we retreive these programatically?                     //if lightspeed entered their items in the dashboard, you will still need to pass the item number to activate the mapping to the tax code.
                line.Qty = 1;
                line.Amount = decimal.Parse(ShippingUPSLabel.Text.Replace("$", ""));
                line.Discounted = false;
                //Not needed: line.ExemptionNo = "";
                //Not needed: line.Ref1 = "client specific reference string 1";   //optional //What are Ref1 and Ref2 used for? Do we have to set them to anything specific?
                //Not needed: line.Ref2 = "client specific reference #2";
                //Not needed: line.RevAcct = "a revenue account";                 //optional //Does this have to be an account number? If so, where do we get this number from?
                line.TaxCode = "FR";                        //How do we get the Tax code? Is it specific to an item or just one general Tax code?
                //a tax code will only need to be passed if the item isn't mapped in the dashboard as you have indicated lightspeed has done
                getTaxrequest.Lines.Add(line);

                getTaxrequest.CompanyCode = System.Configuration.ConfigurationManager.AppSettings["AvataxCompanyCode"].ToString();              //How do we get Lightspeed’s company code for Avatax? on the dashboard organization page

                //getTaxrequest.DocCode = "DOC20051234567";          //What is this field and what do we set it to?  An invoice number (unique and probably sequential)...Lightspeed should be able to tell you what to use here
                //getTaxrequest.DocDate = DateTime.Today;
                //getTaxrequest.DocType = Avalara.AvaTax.Adapter.TaxService.DocumentType.SalesInvoice;
                //getTaxrequest.Discount = 0m;
                //getTaxrequest.ExemptionNo = null;
                //getTaxrequest.DetailLevel = Avalara.AvaTax.Adapter.TaxService.DetailLevel.Tax;
                //getTaxrequest.PurchaserCode = "12345";             //What is this field and what do we set it to?  //optional
                //getTaxrequest.PurchaserType = null;
                //getTaxrequest.SalespersonCode = null;

                Avalara.AvaTax.Adapter.TaxService.TaxSvc taxSvc = new Avalara.AvaTax.Adapter.TaxService.TaxSvc();
                taxSvc.Configuration.Url = System.Configuration.ConfigurationManager.AppSettings["AvataxUrl"].ToString();                   //What is this url?  //url, account, and license key are in an email that Cathy probably got during the welcome call with Chelssie Brown.  Please check with Cathy for this information.
                taxSvc.Configuration.Security.Account = System.Configuration.ConfigurationManager.AppSettings["AvataxAccount"].ToString();  //What do we set this to?
                taxSvc.Configuration.Security.License = System.Configuration.ConfigurationManager.AppSettings["AvataxLicense"].ToString();  //What do we set this to?
                //taxSvc.Configuration.Security.Timeout = timeout;  //Is there a specific timeout we should use?  //set this as you wish...300 is often used.
                Avalara.AvaTax.Adapter.TaxService.GetTaxResult getTaxResult = taxSvc.GetTax(getTaxrequest);

                //return the percentage instead of the amount: decimal.Parse(ShippingUPSLabel.Text.Replace("$", "")) +
                taxableAmount = getTaxResult.TotalTaxable;
                taxAmount = getTaxResult.TotalTax;
                decimal theTax = taxAmount;

                if (taxableAmount != 0.00M)
                    return Math.Round(((theTax / taxableAmount) * decimal.Parse("100.00")), 3);
                else
                    return 0.00M;
            }
            catch (Exception ex)
            {
                ErrorLabel.Text = ex.ToString();
                return 0.00M;
            }
        }