| | | 1 | | using Clave.Expressionify; |
| | | 2 | | using System; |
| | | 3 | | using System.Collections.Generic; |
| | | 4 | | using System.Linq; |
| | | 5 | | using System.Text; |
| | | 6 | | using WinSolutions.Sveta.Server.Data.DataModel.Entities; |
| | | 7 | | |
| | | 8 | | namespace WinSolutions.Sveta.Server.Data.DataModel.Extensions |
| | | 9 | | { |
| | | 10 | | public static class PriceTrendDetailExtensions |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Возвращает актуальную переоценку из списка переоценок |
| | | 14 | | /// </summary> |
| | | 15 | | /// <param name="warehouseId">Id склада-владельца</param> |
| | | 16 | | [Expressionify] |
| | | 17 | | public static PriceTrendDetail Actual(this IEnumerable<PriceTrendDetail> priceTrendDetails, long departmentId) = |
| | 681 | 18 | | priceTrendDetails.Where(x => |
| | 1362 | 19 | | !x.IsDeleted |
| | 1362 | 20 | | && x.PriceTrend.SupplierDepartmentId == departmentId |
| | 1362 | 21 | | && x.PriceTrend.BeginDate <= DateTime.Now) |
| | 1362 | 22 | | .OrderByDescending(x => x.PriceTrend.BeginDate) |
| | 681 | 23 | | .FirstOrDefault(); |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// Скидка в процентах для PriceNew от цены PriceOld |
| | | 27 | | /// </summary> |
| | | 28 | | public static int Discount(this PriceTrendDetail priceTrendDetail) |
| | 0 | 29 | | { |
| | 0 | 30 | | var result = priceTrendDetail.PriceOld.HasValue && priceTrendDetail.PriceOld.Value > priceTrendDetail.PriceN |
| | 0 | 31 | | ? (int)Math.Round(100 - 100 * priceTrendDetail.PriceNew / priceTrendDetail.PriceOld.Value, 0) |
| | 0 | 32 | | : 0; |
| | 0 | 33 | | return result <= 99 ? result : 99; |
| | 0 | 34 | | } |
| | | 35 | | |
| | | 36 | | public static int? DiscountForDisplay(this PriceTrendDetail priceTrendDetail) |
| | 154 | 37 | | { |
| | 154 | 38 | | return priceTrendDetail.Discount.GetValueOrDefault() > 0 ? priceTrendDetail.Discount : (int?)null; |
| | 154 | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Вычисление скидки для отображения ярлыка. Если 0 - ярлык на витрине не будет отображаться |
| | | 43 | | /// </summary> |
| | | 44 | | /// <param name="priceTrendDetail">Детали переоценки</param> |
| | | 45 | | /// <returns>Возвращает значение скидки, если скидка >= 20, иначе 0</returns> |
| | | 46 | | public static int? DiscountForLabelDisplay(this PriceTrendDetail priceTrendDetail) |
| | 0 | 47 | | { |
| | 0 | 48 | | return priceTrendDetail.Discount.GetValueOrDefault() >= 20 ? priceTrendDetail.Discount : 0; |
| | 0 | 49 | | } |
| | | 50 | | } |
| | | 51 | | } |