Exemplo n.º 1
0
    private void BindBillingAddress(OriginAddress billingAddress)
    {
        StringBuilder billingAdr = new StringBuilder();

        billingAdr.Append("<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\"><tr>");
        billingAdr.Append("<td>Customer Name:</td>");
        billingAdr.Append("<td>" + billingAddress.FirstName + " " + billingAddress.LastName + "</td></tr><tr>");
        billingAdr.Append("<td>Address:</td>");
        billingAdr.Append("<td>" + billingAddress.Address1 + "</td></tr><tr>");
        if (!string.IsNullOrEmpty(billingAddress.Address2))
        {
            billingAdr.Append("<td>Address2:</td>");
            billingAdr.Append("<td>" + billingAddress.Address2 + "</td></tr><tr>");
        }
        billingAdr.Append("<td>Country:</td>");
        billingAdr.Append("<td>" + billingAddress.Country + "</td></tr><tr>");
        billingAdr.Append("<td>City:</td>");
        billingAdr.Append("<td>" + billingAddress.City + "</td></tr><tr>");
        billingAdr.Append("<td>State:</td>");
        billingAdr.Append("<td>" + billingAddress.State + "</td></tr><tr>");
        billingAdr.Append("<td>ZipCode:</td>");
        billingAdr.Append("<td>" + billingAddress.Zip + "</td></tr><tr>");
        billingAdr.Append("<td>Email Address:</td>");
        billingAdr.Append("<td>" + billingAddress.Email + "</td></tr><tr>");
        billingAdr.Append("<td>Phone No:</td>");
        billingAdr.Append("<td>" + billingAddress.Phone + "</td></tr>");
        billingAdr.Append("</table>");

        ltBillingAddress.Text    = billingAdr.ToString();
        _fromAddress             = billingAddress;
        _fromAddress.CountryName = "";
        Session["sl_frAddress"]  = _fromAddress;
    }
        public void PostTax(OriginAddress originAddress, CustomerOrder customerOrder)
        {
            if (!this.AvalaraSettings.PostTaxes)  // Added condition to check post taxes setting
            {
                return;
            }
            string str = string.Empty;

            if (ValidateOrderAddressForAvalara(customerOrder))
            {
                try
                {
                    GetTaxRequest  requestFromOrder1    = GetCalcTaxRequestFromOrder(originAddress, customerOrder, DocumentType.SalesInvoice);
                    PostTaxRequest requestFromOrder2    = GetPostTaxRequestFromOrder(customerOrder);
                    TaxSvc         configuredTaxService = GetConfiguredTaxService();
                    configuredTaxService.GetTax(requestFromOrder1);
                    str = this.ProcessAvalaraResponseMessage(configuredTaxService.PostTax(requestFromOrder2));
                }
                catch (Exception ex)
                {
                    LogHelper.For(this).Error("Error running Avalara PostTax method: " + ex.Message, "TaxCalculator_Avalara");
                    throw;
                }
            }
            else
            {
                LogHelper.For(this).Debug("The billto/shipto customer does not have an address specified. In order to calculate tax this must be set up.", "TaxCalculator_Avalara");
                return;
            }
            if (string.IsNullOrEmpty(str))
            {
                return;
            }
            LogHelper.For(this).Debug(str, "Avalara Result, PostTax: ");
        }
        internal LSResponseMessage(PLCMessageTypes messageType, LSRequestMessage source, byte[] data)
            : base(messageType, source.UniqueId)
        {
            OriginRequestType = source.RequestType;
            OriginDataType    = source.DataType;
            OriginAddress     = source.OriginAddress;
            DomainType        = OriginAddress.Substring(1, 1);
            DataType          = OriginAddress?.Substring(2, 1);
            Address           = OriginAddress?.Remove(0, 3);
            Addresses         = (from i in Address?.Split('.')
                                 select int.Parse(i)).ToArray();
            RequestDomainType = source.RequestAddress.Substring(1, 1);
            RequestDataType   = source.RequestAddress.Substring(2, 1);
            RequestAddress    = source.RequestAddress.Remove(0, 3);
            RequestAddresses  = (from i in RequestAddress?.Split('.')
                                 select int.Parse(i)).ToArray();
            switch (messageType)
            {
            case PLCMessageTypes.Ascii:
                _SetAscii(data);
                break;

            case PLCMessageTypes.Binary:
                _SetBinary(data);
                break;
            }
        }
Exemplo n.º 4
0
    //Precondition: None
    //Postcondition:  When this < p2, method returns negative #
    // When this > p2, method returns positive #
    // When this == p2, method returns 0
    public int CompareTo(Parcel p2)
    {
        if (this == null && p2 == null) //both parcel's null?
        {
            return(0);                  //empty
        }

        if (this == null) //parcel 1 is null?
        {
            return(-1);   //null is less than any value
        }

        if (p2 == null) //parcel 2 is null?
        {
            return(1);  //any actual value is greater than null
        }

        if (this.OriginAddress.CompareTo(p2.OriginAddress) != 0) //if this OriginAddress is not equal to p2. OriginAddress
        {
            return(OriginAddress.CompareTo(p2.OriginAddress));   //return comparison value
        }
        else
        {
            return(0); //otherwise, equal
        }
    }
Exemplo n.º 5
0
        //tostring override method to return values of data fields as strings
        //displays costs and fees
        //preconditions: none
        //postconditions: a formatted string for the output
        public override string ToString()
        {
            //simplified newline
            string nl = Environment.NewLine;

            return("Origin Address:" + nl + OriginAddress.ToString() + nl + nl
                   + "Destination Address:" + nl + DestinationAddress.ToString()
                   + nl + "Cost: " + CalcCost().ToString("C"));
        }
        public void CalculateTax(OriginAddress originAddress, CustomerOrder customerOrder)
        {
            Website website = customerOrder.Website;

            if (website == null || customerOrder.OrderLines.Count < 1)
            {
                return;
            }
            if (customerOrder.WebsiteId != null)
            {
                customSettings.OverrideCurrentWebsite(customerOrder.WebsiteId);
            }
            var Excert = customerOrder.ShipTo.CustomProperties.Where(x => x.Name.Equals("EXCert", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            if (Excert != null && !string.IsNullOrEmpty(Excert.Value))
            {
                customerOrder.StateTax = Decimal.Zero;
                return;
            }

            var taxCalculation = this.TaxesSettings.TaxCalculation;

            if (taxCalculation.ToString().EqualsIgnoreCase("Calculate") && ValidateOrderAddressForAvalara(customerOrder))
            {
                var    requestFromOrder     = GetCalcTaxRequestFromOrder(originAddress, customerOrder, DocumentType.SalesOrder);
                var    configuredTaxService = GetConfiguredTaxService();
                string message1;
                try
                {
                    LogHelper.For(this).Info("AvalaraTax call for Order Number " + customerOrder.OrderNumber, "TaxCalculator_Avalara");

                    //BUSA-481 : Tax Exempt. Truncate country code from customer number Starts.
                    requestFromOrder.CustomerCode = !string.IsNullOrEmpty(requestFromOrder.CustomerCode) ? requestFromOrder.CustomerCode.Trim().Substring(1, requestFromOrder.CustomerCode.Length - 1) : string.Empty;
                    //BUSA-481 : Tax Exempt. Truncate country code from customer number Ends.

                    var tax = configuredTaxService.GetTax(requestFromOrder);
                    message1 = ProcessAvalaraResponseMessage(tax);
                    customerOrder.StateTax = tax.TotalTax;
                }
                catch (Exception ex)
                {
                    LogHelper.For(this).Error("Error running Avalara GetTax method:  " + ex.Message, "TaxCalculator_Avalara");
                    throw;
                }
                if (!string.IsNullOrEmpty(message1))
                {
                    LogHelper.For(this).Debug(message1, "Avalara Result, PostTax: ");
                }
            }
            else
            {
                customerOrder.StateTax = Decimal.Zero;
                string message = !taxCalculation.ToString().EqualsIgnoreCase("Calculate") ? "Select taxcalculation as calculate." : "The billto/shipto customer does not have an address specified. In order to calculate tax this must be set up.";
                LogHelper.For(this).Debug(message, "TaxCalculator_Avalara");
            }
        }
Exemplo n.º 7
0
 private void GetOrderDetails(int storeId, int portalId, int orderId, string cultureName)
 {
     try
     {
         OrderLabel orderDetail = GetOrderDetailByOrderId(orderId, storeId, portalId, cultureName);
         if (orderDetail != null)
         {
             OriginAddress billingAddress = GetUserBillingAddress(orderDetail.UserBillingAddressId);
             BindBillingAddress(billingAddress);
             int providerId = GetShippingProviderIdByShippingMethod(orderDetail.ShippingMethodId);
             ProviderSetting(providerId, storeId, portalId);
             Session["labelOrderInfo"]  = orderDetail;
             lblUserShippingMethod.Text = string.Format("{0}:{1}", "User Selected Method:",
                                                        orderDetail.ShippingMethodName);
             DestinationAddress shippingAddress = GetUserShippingAddress(orderDetail.UserShippingAddressId, storeId, portalId);
             BindShippingAddress(shippingAddress);
             AspxCommerce.Core.WareHouseAddress wareHouseAddress = GetWareHouseAddress(storeId, portalId);
             BindWareHouseAddress(wareHouseAddress);
             if (shippingAddress.ToCountry != null && shippingAddress.ToCountry.ToLower().Trim() != "united states" && shippingAddress.ToCountry.ToLower().Trim() != wareHouseAddress.Country.ToLower().Trim())
             {
                 int count = rblLabelTypeList.Items.Count;
                 for (int i = 0; i < count; i++)
                 {
                     rblLabelTypeList.Items[i].Enabled = false;
                 }
                 rblLabelTypeList.Items.Add(new ListItem()
                 {
                     Text     = "International Label",
                     Selected = true,
                     Value    = "internationallabel"
                 });
             }
             BindPackageDetails(orderDetail);
         }
     }
     catch (Exception ex)
     {
         ProcessException(ex);
     }
 }
Exemplo n.º 8
0
 //Override the to string and print the origin, destionation and cost
 public override string ToString()
 {
     return(string.Format("Origin: " + Environment.NewLine +
                          "{0} \n\nDestintion: " + Environment.NewLine + "{1} " + Environment.NewLine + "Costs: {2}",
                          OriginAddress.ToString(), DestinationAddress.ToString(), CalcCost().ToString("C")));
 }
        protected GetTaxRequest GetCalcTaxRequestFromOrder(OriginAddress originAddress, CustomerOrder customerOrder, DocumentType requestDocType)
        {
            //BUSA-483 Tax is not calculating correctly Start
            if (customerOrder != null)
            {
                if (!string.IsNullOrEmpty(customerOrder.BTPostalCode) || !string.IsNullOrEmpty(customerOrder.STPostalCode))
                {
                    //BUSA-730 : Tax & Shipping were getting calculated wrong
                    if (customerOrder.Status.EqualsIgnoreCase("AwaitingApproval"))
                    {
                        isShipToAddressChange = false;
                    } //BUSA-730 : Tax & Shipping were getting calculated wrong
                    else if (customerOrder.BTPostalCode.EqualsIgnoreCase(customerOrder.STPostalCode) && string.IsNullOrEmpty(customerOrder.Customer.CustomerSequence))
                    {
                        isShipToAddressChange = true;
                    }
                    else
                    {
                        isShipToAddressChange = false;
                    }
                }
            }
            var currentCustomer = customerOrder.ShipTo != null && !isShipToAddressChange ? customerOrder.ShipTo : SiteContext.Current.BillTo;

            var FOBCode = string.IsNullOrEmpty(currentCustomer.GetProperty("FOBCode", string.Empty).Trim()) ? "none"
                    : currentCustomer.GetProperty("FOBCode", string.Empty).Trim();

            if (FOBCode == "02")
            {
                customerOrder.ShippingCharges = Decimal.Zero;
            }
            //BUSA-483 Tax is not calculating correctly end

            // BUSA-336 : Taxes are being calculated based on the item value BEFORE promotional discounts are applied Starts
            var promotionOrderDiscountTotal    = customerOrderUtilities.GetPromotionOrderDiscountTotal(customerOrder);
            var promotionShippingDiscountTotal = customerOrderUtilities.GetPromotionShippingDiscountTotal(customerOrder);
            // BUSA-336 : Taxes are being calculated based on the item value BEFORE promotional discounts are applied Ends

            //var companyCode = applicationSettingProvider.GetOrCreateByName<string>("TaxCalculator_Avalara_CompanyCode");
            string companyCode = customSettings.TaxCalculatorAvalaraCompanyCode;
            //var orderDiscountTotal = customerOrder.DiscountAmount; // Commented to pass discounted amount in Avalara.
            var orderDiscountTotal = promotionOrderDiscountTotal;//BUSA-562:Difference in tax amounts between ERP and Insite ($0.01) // BUSA-336 : // BUSA-336 : Taxes are being calculated based on the item value BEFORE promotional discounts are applied Starts.

            var     getTaxRequest = new GetTaxRequest();
            Address address1      = new Address();

            address1.Line1      = originAddress.Address1;
            address1.Line2      = originAddress.Address2;
            address1.Line3      = originAddress.Address3;
            address1.City       = originAddress.City;
            address1.Region     = originAddress.Region;
            address1.PostalCode = originAddress.PostalCode;
            Country country = originAddress.Country;
            string  str1    = country != null ? country.IsoCode2 : string.Empty;

            address1.Country = str1;
            if (address1.Line1.IsBlank())
            {
                throw new InvalidOperationException("The origin address for tax purposes does not have a proper address. In order to calculate tax this must be set up.");
            }

            getTaxRequest.OriginAddress = address1;
            Address address2 = new Address()
            {
                Line1      = customerOrder.STAddress1,
                Line2      = customerOrder.STAddress2,
                Line3      = customerOrder.STAddress3,
                City       = customerOrder.STCity,
                Region     = customerOrder.STState,
                PostalCode = customerOrder.STPostalCode,
                Country    = customerOrder.STCountry
            };

            getTaxRequest.DestinationAddress = address2;
            if (string.IsNullOrEmpty(address2.Line1))
            {
                throw new InvalidOperationException("The current shipto customer does not have an address specified. In order to calculate tax this must be set up.");
            }

            foreach (var orderLine in customerOrder.OrderLines)
            {
                if (!orderLine.Status.EqualsIgnoreCase("Void") && orderLine.Release <= 1)
                {
                    var line = new Line
                    {
                        No          = orderLine.Line.ToString(),
                        ItemCode    = orderLine.Product.ErpNumber,
                        Qty         = (double)orderLine.QtyOrdered,
                        Amount      = this.orderLineUtilities.GetTotalNetPrice(orderLine),
                        Discounted  = orderDiscountTotal != Decimal.Zero,
                        Description = orderLine.Product.ShortDescription,
                        TaxCode     = orderLine.Product.TaxCategory
                    };
                    if (line.TaxCode != null && line.TaxCode.Length >= 24)
                    {
                        line.TaxCode = line.TaxCode.Substring(0, 24);
                    }
                    getTaxRequest.Lines.Add(line);
                }
            }
            if (customerOrder.ShippingCharges > 0)
            {
                var freightLine = new Line()
                {
                    No       = (customerOrder.OrderLines.Count + 1).ToString(),
                    ItemCode = customSettings.TaxCalculatorAvalaraBrasselerShipCode,
                    Qty      = 1,
                    Amount   = customerOrder.ShippingCharges - promotionShippingDiscountTotal,//BUSA-562:Difference in tax amounts between ERP and Insite ($0.01)
                    //    Discounted = customerOrder.DiscountAmount != decimal.Zero -- 4.2
                    Discounted  = orderDiscountTotal != decimal.Zero,
                    Description = customSettings.TaxCalculatorAvalaraBrasselerShipCodeDescription,
                    TaxCode     = customSettings.TaxCalculatorAvalaraBrasselerShippingTaxCode
                };
                if (freightLine.TaxCode != null && freightLine.TaxCode.Length >= 24)
                {
                    freightLine.TaxCode = freightLine.TaxCode.Substring(0, 24);
                }
                getTaxRequest.Lines.Add(freightLine);
            }
            getTaxRequest.CompanyCode  = companyCode;
            getTaxRequest.DocCode      = customerOrder.OrderNumber;
            getTaxRequest.DocDate      = customerOrder.OrderDate.DateTime;
            getTaxRequest.DocType      = requestDocType;
            getTaxRequest.Discount     = orderDiscountTotal;
            getTaxRequest.CustomerCode = customerOrder.CustomerNumber;
            if (customerOrder.ShipTo != null)
            {
                getTaxRequest.CustomerUsageType = customerOrder.ShipTo.TaxCode1;
            }
            return(getTaxRequest);
        }
Exemplo n.º 10
0
        public string BuildXml()
        {
            string result = string.Empty;

            StringWriter  sw = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
            XmlTextWriter xw = new XmlTextWriter(sw);

            xw.Formatting  = Formatting.Indented;
            xw.Indentation = 2;

            xw.WriteStartDocument();

            //Preamble
            xw.WriteStartElement("FDXRateRequest");
            xw.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            xw.WriteAttributeString("xsi:noNamespaceSchemaLocation", "FDXRateRequest.xsd");

            RequestHeader.WriteToXml(xw, "RequestHeader");
            xw.WriteElementString("ReturnShipmentIndicator", ReturnType.ToString());
            xw.WriteElementString("ShipDate", ShipDate.ToString("yyyy-MM-dd"));
            xw.WriteElementString("DropoffType", this.globals.DefaultDropOffType.ToString());
            xw.WriteElementString("Service", Service.ToString());
            xw.WriteElementString("Packaging", Packaging.ToString());
            xw.WriteElementString("WeightUnits", WeightUnits.ToString());
            xw.WriteElementString("Weight", _Weight.ToString("0.0"));
            xw.WriteElementString("ListRate", globals.UseListRates ? "1" : "0");

            OriginAddress.WriteToXml(xw, "OriginAddress");
            DestinationAddress.WriteToXml(xw, "DestinationAddress");

            xw.WriteStartElement("Payment");
            xw.WriteElementString("PayorType", "SENDER");
            xw.WriteEndElement();

            if (Packaging == PackageType.YOURPACKAGING)
            {
                Dimensions.WriteToXml(xw, "Dimensions");
            }

            xw.WriteStartElement("DeclaredValue");
            xw.WriteElementString("Value", _DeclaredValue.ToString("0.00"));
            xw.WriteElementString("CurrencyCode", "USD");
            xw.WriteEndElement();

            if (ContainsAlcohol)
            {
                xw.WriteElementString("Alcohol", "1");
            }
            SpecialServices.WriteToXml(xw, "SpecialServices");
            xw.WriteElementString("PackageCount", PackageCount.ToString());

            //_RequestContact.WriteToXml(xw, "Contact")
            //_RequestAddress.WriteToXml(xw, "Address")

            xw.WriteEndDocument();

            xw.Flush();
            xw.Close();

            result = sw.GetStringBuilder().ToString();

            return(result);
        }
Exemplo n.º 11
0
 // Preconditions: No specific restrictions
 // Postconditions: Returns the data about the parcel as a formatted string.
 public override string ToString()
 {
     return(string.Format("Origin Address:" + OriginAddress.ToString() + System.Environment.NewLine + "Destination Address:" + DestinationAddress.ToString() + System.Environment.NewLine + "Cost:" + CalcCost()));
 }
Exemplo n.º 12
0
 // Preconditions: No specific restrictions
 // Postconditions: Returns the data about the letter as a formatted string.
 public override string ToString()
 {
     return(string.Format("Origin Address: " + System.Environment.NewLine + OriginAddress.ToString() + "\n\nDestination Address: " + System.Environment.NewLine + DestinationAddress.ToString() + "\n\nCost: " + CalcCost().ToString("c") + System.Environment.NewLine + "------------------------------------"));
 }