public static Tuple<decimal, decimal> AddDiscountToPrice(tbl_Discount discount, decimal price, decimal tax, int domainID) { IDomain domainService = (IDomain)DependencyResolver.Current.GetService<IDomain>(); bool useTax = domainService.GetSettingsValueAsBool(SettingsKey.useTax, domainID); bool priceIncludesVat = domainService.GetSettingsValueAsBool(SettingsKey.priceDisplayIncludesVAT, domainID); decimal totalPrice = useTax ? priceIncludesVat ? price : price + tax : price; if (discount.D_IsPercentage) totalPrice -= totalPrice * (discount.D_Value / 100); else totalPrice -= discount.D_Value; if (totalPrice < 0) totalPrice = 0; if (!useTax) return new Tuple<decimal, decimal>(totalPrice, 0); decimal taxPercentage = price != 0 ? priceIncludesVat ? (100 * tax) / price : (100 * tax) / (price + tax) : 0; price = priceIncludesVat ? totalPrice : totalPrice - totalPrice * (taxPercentage / 100); tax = totalPrice * (taxPercentage / 100); if (price < 0) price = tax = 0; return new Tuple<decimal,decimal>(price, tax); }
public static decimal GetDiscountAmount(tbl_Discount discount, decimal price, decimal tax, int domainID) { IDomain domainService = (IDomain)DependencyResolver.Current.GetService<IDomain>(); bool useTax = domainService.GetSettingsValueAsBool(SettingsKey.useTax, domainID); bool priceIncludesVat = domainService.GetSettingsValueAsBool(SettingsKey.priceDisplayIncludesVAT, domainID); decimal totalPrice = useTax ? priceIncludesVat ? price : price + tax : price; return discount.D_IsPercentage ? totalPrice * (discount.D_Value / 100) : discount.D_Value; }
/// <summary> /// Create a new tbl_Discount object. /// </summary> /// <param name="discountID">Initial value of the DiscountID property.</param> /// <param name="d_Code">Initial value of the D_Code property.</param> /// <param name="d_Value">Initial value of the D_Value property.</param> /// <param name="d_Title">Initial value of the D_Title property.</param> /// <param name="d_IsPercentage">Initial value of the D_IsPercentage property.</param> /// <param name="d_DomainID">Initial value of the D_DomainID property.</param> public static tbl_Discount Createtbl_Discount(global::System.Int32 discountID, global::System.String d_Code, global::System.Decimal d_Value, global::System.String d_Title, global::System.Boolean d_IsPercentage, global::System.Int32 d_DomainID) { tbl_Discount tbl_Discount = new tbl_Discount(); tbl_Discount.DiscountID = discountID; tbl_Discount.D_Code = d_Code; tbl_Discount.D_Value = d_Value; tbl_Discount.D_Title = d_Title; tbl_Discount.D_IsPercentage = d_IsPercentage; tbl_Discount.D_DomainID = d_DomainID; return tbl_Discount; }
/// <summary> /// Deprecated Method for adding a new object to the tbl_Discount EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddTotbl_Discount(tbl_Discount tbl_Discount) { base.AddObject("tbl_Discount", tbl_Discount); }