public static double LandedCost(this IInventoryBasePriceInfo info) { double _LandedCost; _LandedCost = info.WholesaleCost + info.Freight + info.Extra + info.Duty; return(_LandedCost); }
public static PriceScheduleView GetView_RegularPrice ( this IInvPrice TodaysInvPriceRecord , short PriceScheduleToUse , IInventoryBasePriceInfo BasePriceInfo ) { PriceScheduleView view; view = BasePriceInfo.CalculatePrice(TodaysInvPriceRecord); return(view); }
public static string GetContents(this IInventoryBasePriceInfo info) { string json = string.Empty; try { json = JsonSerializer.Serialize(info); } catch { json = "{ error: \"Failed to serialize\"}"; } return(json); }
public static PriceScheduleView CalculatePrice(this IInventoryBasePriceInfo info, IInvPrice price) { double WholesaleCost = info.WholesaleCost; double LandedCost = info.LandedCost(); double?Price0 = null; double?ListPrice = null; double?CashPrice = null; double?SalePrice = null; double?PriceToCalculate = null; Price0 = info.RegularPrice_0_Calculated; ListPrice = info.RegularPrice_List_Calculated; CashPrice = info.RegularPrice_Cash_Calculated; SalePrice = info.SalePrice_0_Calculated; string info_json = string.Empty; string nl = Environment.NewLine; try { PriceToCalculate = CalcPrice ( price.RScheduleType , price.RegularPrice , WholesaleCost , LandedCost , CashPrice , SalePrice , ListPrice ); } catch (ArgumentNullException e) { info_json = GetContents(info); Console.WriteLine($"Error: failed to calculate Web Price" + $"({info.ScheduleLevel_List}). " + "Details: " + e.Message + nl + info_json); } PriceScheduleView view = new PriceScheduleView(); view.Level = price.ScheduleLevel; view.Percentage = price.RegularPrice; view.Price = (decimal)PriceToCalculate; view.Code = price.RScheduleType; return(view); }
public static IEnumerable <PriceScheduleView> CalculatePrices ( this IInventoryBasePriceInfo info , IEnumerable <IInvPrice> invPrices ) { double WholesaleCost = info.WholesaleCost; double LandedCost = info.LandedCost(); double?Price0 = null; double?ListPrice = null; double?CashPrice = null; double?SalePrice = null; info.CalculateBasePrices(); Price0 = info.RegularPrice_0_Calculated; ListPrice = info.RegularPrice_List_Calculated; CashPrice = info.RegularPrice_Cash_Calculated; SalePrice = info.SalePrice_0_Calculated; string info_json = string.Empty; string nl = Environment.NewLine; Func <IInvPrice, double> calc = (x) => { try { return(CalcPrice ( x.RScheduleType , x.RegularPrice , WholesaleCost , LandedCost , CashPrice , SalePrice , ListPrice )); } catch (ArgumentNullException e) { info_json = GetContents(info); Console.WriteLine($"Error: failed to calculate Web Price" + $"({info.ScheduleLevel_List}). " + "Details: " + e.Message + nl + info_json); return(0); } }; var views = invPrices.Select ( price => new PriceScheduleView() { Code = price.RScheduleType , InventoryUnique = price.PartUnique , Level = price.ScheduleLevel , Percentage = price.RegularPrice , Price = (decimal)calc(price) } ); #region linq above turned into foreach if (false) { List <PriceScheduleView> Vs = new List <PriceScheduleView>(); foreach (var price in invPrices) { Vs.Add ( new PriceScheduleView() { Code = price.RScheduleType , InventoryUnique = price.PartUnique , Level = price.ScheduleLevel , Percentage = price.RegularPrice , Price = (decimal)calc(price) } ); } } #endregion linq above turned into foreach return(views); }
public static IInventoryBasePriceInfo CalculateBasePrices(this IInventoryBasePriceInfo info) { double WholesaleCost = info.WholesaleCost; double LandedCost = info.LandedCost(); double?Price0 = null; double?ListPrice = null; double?CashPrice = null; double?SalePrice = null; string info_json = string.Empty; string nl = Environment.NewLine; if (info.SKU == "8702418") { string x = info.SKU; } try { Price0 = CalcPrice ( info.RScheduleType_0 , info.RegularPrice_0 , WholesaleCost , LandedCost , CashPrice , SalePrice , ListPrice ); } catch (ArgumentNullException e) { info_json = GetContents(info); Console.WriteLine($"Error: failed to calculate retail for price schedule 0" + $"({info.ScheduleLevel_0}). " + "Details: " + e.Message + nl + info_json); } try { ListPrice = CalcPrice ( info.RScheduleType_List , info.RegularPrice_List , WholesaleCost , LandedCost , CashPrice , SalePrice , ListPrice ); } catch (ArgumentNullException e) { info_json = GetContents(info); Console.WriteLine($"Error: failed to calculate retail for List Price" + $"({info.ScheduleLevel_List}). " + "Details: " + e.Message + nl + info_json); } try { CashPrice = CalcPrice ( info.RScheduleType_Cash , info.RegularPrice_Cash , WholesaleCost , LandedCost , CashPrice , SalePrice , ListPrice ); } catch (ArgumentNullException e) { info_json = GetContents(info); Console.WriteLine($"Error: failed to calculate retail for Cash Price" + $"({info.ScheduleLevel_List}). " + "Details: " + e.Message + nl + info_json); } try { SalePrice = CalcPrice ( info.SScheduleType_0 , info.SalePrice_0 , WholesaleCost , LandedCost , CashPrice , SalePrice , ListPrice ); } catch (ArgumentNullException e) { info_json = GetContents(info); Console.WriteLine($"Error: failed to calculate Sale Price" + $"({info.ScheduleLevel_List}). " + "Details: " + e.Message + nl + info_json); } info.RegularPrice_0_Calculated = CNull(Price0); info.RegularPrice_List_Calculated = CNull(ListPrice); info.RegularPrice_Cash_Calculated = CNull(CashPrice); info.SalePrice_0_Calculated = CNull(SalePrice); return(info); }