Example #1
0
        /// <summary>
        /// Calculate a price adjustment according to adjustment type
        /// </summary>
        /// <param name="price">Price to adjust</param>
        /// <param name="priceAdjustmentType">The type of price adjustment calculation (e.g. absolute adjustment)</param>
        /// <param name="priceAdjustment">The value for price adjustment calculation</param>
        /// <returns>Adjusted price</returns>
        public decimal GetAdjustedPrice(decimal price,
                                        PriceAdjustmentTypeEnum priceAdjustmentType, decimal priceAdjustment)
        {
            decimal result = price;

            switch (PriceAdjustmentType)
            {
            case PriceAdjustmentTypeEnum.AbsoluteAdjustment:
            {
                result -= PriceAdjustment;
            }
            break;

            case PriceAdjustmentTypeEnum.AbsolutePrice:
            {
            }
            break;

            case PriceAdjustmentTypeEnum.RelativeAdjustment:
            {
                result = result * ((100 - PriceAdjustment) / 100);
            }
            break;

            default:
                break;
            }

            if (result < decimal.Zero)
            {
                result = decimal.Zero;
            }

            return(result);
        }
        protected void SavePricelistChanges(int priceListId)
        {
            foreach (GridViewRow objRow in gvProductVariants.Rows)
            {
                if (objRow.RowType == DataControlRowType.DataRow)
                {
                    CheckBox       chkSelected                 = objRow.FindControl("chkSelected") as CheckBox;
                    DropDownList   ddlPriceAdjustmentType      = objRow.FindControl("ddlPriceAdjustmentType") as DropDownList;
                    DecimalTextBox txtPriceAdjustment          = objRow.FindControl("txtPriceAdjustment") as DecimalTextBox;
                    HiddenField    hfProductVariantPricelistId = objRow.FindControl("hfProductVariantPricelistId") as HiddenField;
                    HiddenField    hfProductVariantId          = objRow.FindControl("hfProductVariantId") as HiddenField;

                    int productVariantPricelistId = 0;
                    int.TryParse(hfProductVariantPricelistId.Value, out productVariantPricelistId);

                    ProductVariantPricelist productVariantPricelist = this.ProductService.GetProductVariantPricelistById(productVariantPricelistId);
                    if (chkSelected.Checked)
                    {
                        int productVariantId = 0;
                        int.TryParse(hfProductVariantId.Value, out productVariantId);

                        PriceAdjustmentTypeEnum priceAdjustmentType = (PriceAdjustmentTypeEnum)Enum.ToObject(typeof(PriceAdjustmentTypeEnum), int.Parse(ddlPriceAdjustmentType.SelectedItem.Value));
                        decimal priceAdjustment = txtPriceAdjustment.Value;

                        if (productVariantPricelist != null)
                        {
                            productVariantPricelist.ProductVariantId      = productVariantId;
                            productVariantPricelist.PricelistId           = priceListId;
                            productVariantPricelist.PriceAdjustmentTypeId = (int)priceAdjustmentType;
                            productVariantPricelist.PriceAdjustment       = priceAdjustment;
                            productVariantPricelist.UpdatedOn             = DateTime.UtcNow;
                            this.ProductService.UpdateProductVariantPricelist(productVariantPricelist);
                        }
                        else
                        {
                            productVariantPricelist = new ProductVariantPricelist();
                            productVariantPricelist.ProductVariantId      = productVariantId;
                            productVariantPricelist.PricelistId           = priceListId;
                            productVariantPricelist.PriceAdjustmentTypeId = (int)priceAdjustmentType;
                            productVariantPricelist.PriceAdjustment       = priceAdjustment;
                            productVariantPricelist.UpdatedOn             = DateTime.UtcNow;
                            this.ProductService.InsertProductVariantPricelist(productVariantPricelist);
                        }
                    }
                    else
                    {
                        if (productVariantPricelist != null)
                        {
                            this.ProductService.DeleteProductVariantPricelist(productVariantPricelistId);
                        }
                    }
                }
            }
        }
        protected void SavePricelistChanges(int priceListID)
        {
            foreach (GridViewRow objRow in gvProductVariants.Rows)
            {
                if (objRow.RowType == DataControlRowType.DataRow)
                {
                    CheckBox       chkSelected                 = objRow.FindControl("chkSelected") as CheckBox;
                    DropDownList   ddlPriceAdjustmentType      = objRow.FindControl("ddlPriceAdjustmentType") as DropDownList;
                    DecimalTextBox txtPriceAdjustment          = objRow.FindControl("txtPriceAdjustment") as DecimalTextBox;
                    HiddenField    hfProductVariantPricelistID = objRow.FindControl("hfProductVariantPricelistID") as HiddenField;
                    HiddenField    hfProductVariantID          = objRow.FindControl("hfProductVariantID") as HiddenField;

                    int productVariantPricelistID = 0;
                    int.TryParse(hfProductVariantPricelistID.Value, out productVariantPricelistID);

                    ProductVariantPricelist productVariantPricelist = ProductManager.GetProductVariantPricelistByID(productVariantPricelistID);
                    if (chkSelected.Checked)
                    {
                        int productVariantID = 0;
                        int.TryParse(hfProductVariantID.Value, out productVariantID);

                        PriceAdjustmentTypeEnum priceAdjustmentType = (PriceAdjustmentTypeEnum)Enum.ToObject(typeof(PriceAdjustmentTypeEnum), int.Parse(ddlPriceAdjustmentType.SelectedItem.Value));
                        decimal priceAdjustment = txtPriceAdjustment.Value;

                        if (productVariantPricelist != null)
                        {
                            productVariantPricelist = ProductManager.UpdateProductVariantPricelist(productVariantPricelistID, productVariantPricelist.ProductVariantID,
                                                                                                   productVariantPricelist.PricelistID, priceAdjustmentType, priceAdjustment, DateTime.Now);
                        }
                        else
                        {
                            productVariantPricelist = ProductManager.InsertProductVariantPricelist(productVariantID,
                                                                                                   priceListID, priceAdjustmentType, priceAdjustment, DateTime.Now);
                        }
                    }
                    else
                    {
                        if (productVariantPricelist != null)
                        {
                            ProductManager.DeleteProductVariantPricelist(productVariantPricelistID);
                        }
                    }
                }
            }
        }
Example #4
0
        public Pricelist SaveInfo()
        {
            int affiliateId = int.Parse(ddlAffiliate.SelectedValue);

            PriceListExportModeEnum exportMode          = (PriceListExportModeEnum)Enum.ToObject(typeof(PriceListExportModeEnum), int.Parse(this.ddlExportMode.SelectedItem.Value));
            PriceListExportTypeEnum exportType          = (PriceListExportTypeEnum)Enum.ToObject(typeof(PriceListExportTypeEnum), int.Parse(this.ddlExportType.SelectedItem.Value));
            PriceAdjustmentTypeEnum priceAdjustmentType = (PriceAdjustmentTypeEnum)Enum.ToObject(typeof(PriceAdjustmentTypeEnum), int.Parse(this.ddlPriceAdjustmentType.SelectedItem.Value));
            decimal priceAdjustment = txtPriceAdjustment.Value;

            Pricelist pricelist = ProductManager.GetPricelistById(this.PricelistId);

            if (pricelist != null)
            {
                pricelist = ProductManager.UpdatePricelist(pricelist.PricelistId,
                                                           exportMode, exportType, affiliateId, this.txtDisplayName.Text,
                                                           this.txtShortName.Text, this.txtPricelistGuid.Text, this.txtCacheTime.Value,
                                                           this.ddlFormatLocalization.SelectedValue, this.txtDescription.Text,
                                                           this.txtAdminNotes.Text, this.txtHeader.Text, this.txtBody.Text, this.txtFooter.Text,
                                                           priceAdjustmentType, this.txtPriceAdjustment.Value, this.chkOverrideIndivAdjustment.Checked,
                                                           pricelist.CreatedOn, DateTime.UtcNow);

                SavePricelistChanges(pricelist.PricelistId);
            }
            else
            {
                pricelist = ProductManager.InsertPricelist(
                    exportMode, exportType, affiliateId, this.txtDisplayName.Text,
                    this.txtShortName.Text, this.txtPricelistGuid.Text, this.txtCacheTime.Value, this.ddlFormatLocalization.SelectedValue,
                    this.txtDescription.Text, this.txtAdminNotes.Text, this.txtHeader.Text, this.txtBody.Text, this.txtFooter.Text,
                    priceAdjustmentType, priceAdjustment, chkOverrideIndivAdjustment.Checked,
                    DateTime.UtcNow, DateTime.UtcNow);

                SavePricelistChanges(pricelist.PricelistId);
            }

            return(pricelist);
        }
        /// <summary>
        /// Updates the ProductVariantPricelist
        /// </summary>
        /// <param name="ProductVariantPricelistID">The product variant pricelist identifier</param>
        /// <param name="ProductVariantID">The product variant identifer</param>
        /// <param name="PricelistID">The pricelist identifier</param>
        /// <param name="PriceAdjustmentType">The type of price adjustment (if used) (relative or absolute)</param>
        /// <param name="PriceAdjustment">The price will be adjusted by this amount</param>
        /// <param name="UpdatedOn">The date and time of instance update</param>
        /// <returns>ProductVariantPricelist</returns>
        public static ProductVariantPricelist UpdateProductVariantPricelist(int ProductVariantPricelistID, int ProductVariantID, int PricelistID,
            PriceAdjustmentTypeEnum PriceAdjustmentType, decimal PriceAdjustment,
            DateTime UpdatedOn)
        {
            if (ProductVariantPricelistID == 0)
                return null;

            UpdatedOn = DateTimeHelper.ConvertToUtcTime(UpdatedOn);

            DBProductVariantPricelist dbItem = DBProviderManager<DBProductProvider>.Provider.UpdateProductVariantPricelist(ProductVariantPricelistID,
                ProductVariantID, PricelistID, (int)PriceAdjustmentType,
                PriceAdjustment, UpdatedOn);
            ProductVariantPricelist newProductVariantPricelist = DBMapping(dbItem);

            return newProductVariantPricelist;
        }
        /// <summary>
        /// Updates the Pricelist
        /// </summary>
        /// <param name="PricelistID">Unique Identifier</param>
        /// <param name="ExportMode">Mode of list creation (Export all, assigned only, assigned only with special price)</param>
        /// <param name="ExportType">CSV or XML</param>
        /// <param name="AffiliateID">Affiliate connected to this pricelist (optional), links will be created with AffiliateID</param>
        /// <param name="DisplayName">Displayedname</param>
        /// <param name="ShortName">shortname to identify the pricelist</param>
        /// <param name="PricelistGuid">unique identifier to get pricelist "anonymous"</param>
        /// <param name="CacheTime">how long will the pricelist be in cached before new creation</param>
        /// <param name="FormatLocalization">what localization will be used (numeric formats, etc.) en-US, de-DE etc.</param>
        /// <param name="Description">Displayed description</param>
        /// <param name="AdminNotes">Admin can put some notes here, not displayed in public</param>
        /// <param name="Header">Headerline of the exported file (plain text)</param>
        /// <param name="Body">template for an exportet productvariant, uses delimiters and replacement strings</param>
        /// <param name="Footer">Footer line of the exportet file (plain text)</param>
        /// <param name="PriceAdjustmentType">type of price adjustment (if used) (relative or absolute)</param>
        /// <param name="PriceAdjustment">price will be adjusted by this amount (in accordance with PriceAdjustmentType)</param>
        /// <param name="OverrideIndivAdjustment">use individual adjustment, if available, or override</param>
        /// <param name="CreatedOn">when was this record originally created</param>
        /// <param name="UpdatedOn">last time this recordset was updated</param>
        /// <returns>Pricelist</returns>
        public static Pricelist UpdatePricelist(int PricelistID, PriceListExportModeEnum ExportMode, PriceListExportTypeEnum ExportType, int AffiliateID,
            string DisplayName, string ShortName, string PricelistGuid, int CacheTime, string FormatLocalization,
            string Description, string AdminNotes,
            string Header, string Body, string Footer,
            PriceAdjustmentTypeEnum PriceAdjustmentType, decimal PriceAdjustment, bool OverrideIndivAdjustment,
            DateTime CreatedOn, DateTime UpdatedOn)
        {
            CreatedOn = DateTimeHelper.ConvertToUtcTime(CreatedOn);
            UpdatedOn = DateTimeHelper.ConvertToUtcTime(UpdatedOn);

            DBPricelist dbItem = DBProviderManager<DBProductProvider>.Provider.UpdatePricelist(PricelistID, (int)ExportMode,
                (int)ExportType, AffiliateID, DisplayName, ShortName, PricelistGuid,
                CacheTime, FormatLocalization, Description, AdminNotes, Header, Body, Footer,
                (int)PriceAdjustmentType, PriceAdjustment, OverrideIndivAdjustment,
                CreatedOn, UpdatedOn);
            Pricelist newPricelist = DBMapping(dbItem);

            return newPricelist;
        }
        public Pricelist SaveInfo()
        {
            int affiliateId = int.Parse(ddlAffiliate.SelectedValue);

            PriceListExportModeEnum exportMode          = (PriceListExportModeEnum)Enum.ToObject(typeof(PriceListExportModeEnum), int.Parse(this.ddlExportMode.SelectedItem.Value));
            PriceListExportTypeEnum exportType          = (PriceListExportTypeEnum)Enum.ToObject(typeof(PriceListExportTypeEnum), int.Parse(this.ddlExportType.SelectedItem.Value));
            PriceAdjustmentTypeEnum priceAdjustmentType = (PriceAdjustmentTypeEnum)Enum.ToObject(typeof(PriceAdjustmentTypeEnum), int.Parse(this.ddlPriceAdjustmentType.SelectedItem.Value));
            decimal priceAdjustment = txtPriceAdjustment.Value;

            Pricelist pricelist = this.ProductService.GetPricelistById(this.PricelistId);

            if (pricelist != null)
            {
                pricelist.ExportModeId       = (int)exportMode;
                pricelist.ExportTypeId       = (int)exportType;
                pricelist.AffiliateId        = affiliateId;
                pricelist.DisplayName        = this.txtDisplayName.Text;
                pricelist.ShortName          = this.txtShortName.Text;
                pricelist.PricelistGuid      = this.txtPricelistGuid.Text;
                pricelist.CacheTime          = this.txtCacheTime.Value;
                pricelist.FormatLocalization = this.ddlFormatLocalization.SelectedValue;
                pricelist.Description        = this.txtDescription.Text;
                pricelist.AdminNotes         = this.txtAdminNotes.Text;
                pricelist.Header             = this.txtHeader.Text;
                pricelist.Body   = this.txtBody.Text;
                pricelist.Footer = this.txtFooter.Text;
                pricelist.PriceAdjustmentTypeId   = (int)priceAdjustmentType;
                pricelist.PriceAdjustment         = priceAdjustment;
                pricelist.OverrideIndivAdjustment = chkOverrideIndivAdjustment.Checked;
                pricelist.UpdatedOn = DateTime.UtcNow;

                this.ProductService.UpdatePricelist(pricelist);

                SavePricelistChanges(pricelist.PricelistId);
            }
            else
            {
                pricelist = new Pricelist();
                pricelist.ExportModeId       = (int)exportMode;
                pricelist.ExportTypeId       = (int)exportType;
                pricelist.AffiliateId        = affiliateId;
                pricelist.DisplayName        = this.txtDisplayName.Text;
                pricelist.ShortName          = this.txtShortName.Text;
                pricelist.PricelistGuid      = this.txtPricelistGuid.Text;
                pricelist.CacheTime          = this.txtCacheTime.Value;
                pricelist.FormatLocalization = this.ddlFormatLocalization.SelectedValue;
                pricelist.Description        = this.txtDescription.Text;
                pricelist.AdminNotes         = this.txtAdminNotes.Text;
                pricelist.Header             = this.txtHeader.Text;
                pricelist.Body   = this.txtBody.Text;
                pricelist.Footer = this.txtFooter.Text;
                pricelist.PriceAdjustmentTypeId   = (int)priceAdjustmentType;
                pricelist.PriceAdjustment         = priceAdjustment;
                pricelist.OverrideIndivAdjustment = chkOverrideIndivAdjustment.Checked;
                pricelist.CreatedOn = DateTime.UtcNow;
                pricelist.UpdatedOn = DateTime.UtcNow;

                this.ProductService.InsertPricelist(pricelist);

                SavePricelistChanges(pricelist.PricelistId);
            }

            return(pricelist);
        }
Example #8
0
        /// <summary>
        /// Calculate a price adjustment according to adjustment type
        /// </summary>
        /// <param name="price">Price to adjust</param>
        /// <param name="priceAdjustmentType">The type of price adjustment calculation (e.g. absolute adjustment)</param>
        /// <param name="priceAdjustment">The value for price adjustment calculation</param>
        /// <returns>Adjusted price</returns>
        public decimal GetAdjustedPrice(decimal price, 
            PriceAdjustmentTypeEnum priceAdjustmentType, decimal priceAdjustment)
        {
            decimal result = price;

            switch (PriceAdjustmentType)
            {
                case PriceAdjustmentTypeEnum.AbsoluteAdjustment:
                    {
                        result -= PriceAdjustment;
                    }
                    break;
                case PriceAdjustmentTypeEnum.AbsolutePrice:
                    {
                    }
                    break;
                case PriceAdjustmentTypeEnum.RelativeAdjustment:
                    {
                        result = result * ((100 - PriceAdjustment) / 100);
                    }
                    break;
                default:
                    break;
            }

            if (result < decimal.Zero)
                result = decimal.Zero;

            return result;
        }