Ejemplo n.º 1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="OrderDetails"></param>
 /// <param name="config"></param>
 /// <returns></returns>
 public PricingDetail GetPricingDetails(OrderDetailInformation OrderDetails, NorthwindConfig config)
 {
     PricingDetail result;
     Product product = new Product();
     result = product.GetPricingDetails(OrderDetails, config);
     return result;
 }
Ejemplo n.º 2
0
        public PricingDetail GetPricingDetails(OrderDetailInformation OrderDetails, NorthwindConfig config)
        {
            PricingDetail result = new PricingDetail();
            string customerID;
            int productId;
            List<int> productIds = new List<int>();

            int recordCount;

            if (!OrderDetails.Currency.Equals(config.CurrencyCode, StringComparison.InvariantCultureIgnoreCase))
            {
                result.Result = false;
                result.ErrorMessage = Resources.ErrorMessages_CurrencyNotSupported;
                return result;
            }

            if (!OrderDetails.PricingListId.Equals(Constants.DefaultValues.PriceList.ID, StringComparison.InvariantCultureIgnoreCase))
            {
                result.Result = false;
                result.ErrorMessage = Resources.ErrorMessages_PriceListNotSupported;
                return result;
            }

            if (OrderDetails.AccountId == null)
            {
                result.Result = false;
                result.ErrorMessage = Resources.ErrorMessages_AccountNotFound;
                return result;
            }

            customerID = OrderDetails.AccountId;
            if (!(customerID.StartsWith(Constants.CustomerIdPrefix, StringComparison.InvariantCultureIgnoreCase)))
            {
                result.Result = false;
                result.ErrorMessage = Resources.ErrorMessages_OnlyCustomersSupported;
                return result;
            }

            customerID = customerID.Substring(Constants.CustomerIdPrefix.Length);
            DataSet dataSet = new DataSet();
            OleDbDataAdapter dataAdapter;
            string sqlQuery = "Select * from Customers where CustomerID = '" + customerID + "'";

            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                dataAdapter = new OleDbDataAdapter(sqlQuery, connection);
                if (dataAdapter.Fill(dataSet, "Customers") == 0)
                {
                    result.Result = false;
                    result.ErrorMessage = Resources.ErrorMessages_AccountNotFound;
                    return result;
                }
            }

            result.Result = true;
            result.ErrorMessage = "";

            result.PricingListId = Constants.DefaultValues.PriceList.ID;

            DataSets.Product product = new DataSets.Product();
            using (OleDbConnection connection = new OleDbConnection(config.ConnectionString))
            {
                DataSets.ProductTableAdapters.ProductsTableAdapter tableAdapter;
                tableAdapter = new DataSets.ProductTableAdapters.ProductsTableAdapter();
                tableAdapter.Connection = connection;
                recordCount = tableAdapter.Fill(product.Products);
            }

            result.PricingDetailLineItems = new PricingDetailLineItem[OrderDetails.LineItemDetails.Length];
            DataSets.Product.ProductsRow row;
            decimal totalPrice = 0;
            decimal totalLineItemDiscount = 0;
            result.ErrorMessage = "";
            for (int index = 0; index < OrderDetails.LineItemDetails.Length; index++)
            {
                result.PricingDetailLineItems[index] = new PricingDetailLineItem();
                result.PricingDetailLineItems[index].Description = OrderDetails.LineItemDetails[index].Description;
                result.PricingDetailLineItems[index].LineItemId = OrderDetails.LineItemDetails[index].LineItemId;
                result.PricingDetailLineItems[index].LineType = OrderDetails.LineItemDetails[index].LineType;
                result.PricingDetailLineItems[index].SynchMessage = "";

                try
                {
                    productId = Convert.ToInt32(OrderDetails.LineItemDetails[index].ProductId);
                }
                catch (Exception)
                {
                    result.PricingDetailLineItems[index].SynchMessage = String.Format(Resources.ErrorMessages_ProductIdWrongFormat, OrderDetails.LineItemDetails[index].ProductId.ToString());
                    result.ErrorMessage += result.PricingDetailLineItems[index].SynchMessage + "\r\n";
                    result.Result = false;
                    continue;
                }
                if (productIds.Contains(productId))
                {
                    result.PricingDetailLineItems[index].SynchMessage = String.Format(Resources.ErrorMessages_OrderWithProductTwice, productId);
                    //result.ErrorMessage += result.PricingDetailLineItems[index].SynchMessage + "\r\n";
                    //result.Result = false;
                    //continue;
                }

                productIds.Add(productId);

                row = product.Products.FindByProductID(productId);
                if (row == null)
                {
                    result.PricingDetailLineItems[index].SynchMessage = String.Format(Resources.ErrorMessages_ProductIdNotFound, productId);
                    result.ErrorMessage += result.PricingDetailLineItems[index].SynchMessage + "\r\n";
                    result.Result = false;
                    continue;
                }

                //result.PricingDetailLineItems[index].RepricingStatus = ??;

                //result.PricingDetailLineItems[index].StockQuantity = row.IsUnitsInStockNull() ? 0 : (int)row.UnitsInStock;

                result.PricingDetailLineItems[index].ListPrice = row.IsUnitPriceNull() ? (decimal)0 : row.UnitPrice;

                result.PricingDetailLineItems[index].Tax = 0;
                //result.PricingDetailLineItems[index].TaxRate = "no Tax";
                result.PricingDetailLineItems[index].TaxRate = "0";

                result.PricingDetailLineItems[index].DiscountRate = 0;
                result.PricingDetailLineItems[index].Discount = 0;
                if (OrderDetails.LineItemDetails[index].Quantity >= 10)
                {
                    result.PricingDetailLineItems[index].DiscountRate = 10;
                    result.PricingDetailLineItems[index].Discount = 10;
                }

                result.PricingDetailLineItems[index].DiscountSum = ((result.PricingDetailLineItems[index].DiscountRate / 100)) * result.PricingDetailLineItems[index].ListPrice;

                result.PricingDetailLineItems[index].QuotedPrice = result.PricingDetailLineItems[index].ListPrice * (1 - (result.PricingDetailLineItems[index].DiscountRate / 100));
                result.PricingDetailLineItems[index].QuotedPriceTotal = OrderDetails.LineItemDetails[index].Quantity * result.PricingDetailLineItems[index].QuotedPrice;
                totalPrice += result.PricingDetailLineItems[index].QuotedPriceTotal;
                totalLineItemDiscount += OrderDetails.LineItemDetails[index].Quantity * result.PricingDetailLineItems[index].DiscountSum;
            }

            result.DiscountAmt = 0;
            result.DiscountPC = 0;
            result.DiscountType = "";
            result.GrossAmt = totalPrice;
            result.LineItemDisc = totalLineItemDiscount;
            result.NetAmt = totalPrice;
            //result.NoDiscAmt = 0; //????
            result.PricingListId = OrderDetails.PricingListId;
            result.OrderQuoteId = OrderDetails.OrderQuoteId;
            //result.Reference = "";
            result.Tax = 0;

            return result;
        }