public void AddTicketDiscount(DiscountType type, decimal amount, int userId) { var c = Discounts.SingleOrDefault(x => x.DiscountType == (int)type); if (c == null) { c = new Discount { DiscountType = (int)type, Amount = amount }; Discounts.Add(c); } if (amount == 0) { Discounts.Remove(c); } c.UserId = userId; c.Amount = amount; }
private void CalculateDiscount() { //total discount from giftcards decimal giftCardDiscount = Discounts.Where(x => x.GetType() == typeof(GiftVoucher)).Sum(x => x.Amount); //we know we can only have one offer voucher, so SingleOrDefault will either return the voucher, or null OfferVoucher voucher = (OfferVoucher)Discounts.SingleOrDefault(x => x.GetType() == typeof(OfferVoucher)); if (voucher == null) { DiscountTotal = giftCardDiscount; return; } decimal voucherDiscount = 0; //if the voucher is applied to a certain category, return the sum of products in the category, else return the sum of all the products in the basket. decimal voucherCategoryProductTotal = voucher.Category != null?Products.Where(x => x.Product.Category == voucher.Category).Sum(x => x.Total) : SubTotal; voucherDiscount = voucherCategoryProductTotal > voucher.Amount ? voucher.Amount : voucherCategoryProductTotal; //if the discountable total is less than the discounts added, then the max discount is used - this is because giftcards aren't available for discount. DiscountTotal = DiscountableTotal < giftCardDiscount + voucherDiscount ? DiscountableTotal : giftCardDiscount + voucherDiscount; }
public void DataCatalogsFill() { try { _logger.Debug("DataCatalogsFill start"); //OperationResultValue<UpdateResult> res = DBProvider.Client.GetUpdatesForSession(""); //var res2 = res.Result.UpdatedData[0] as OrderToGo; OnDataCatalogMessage("Загружаю список операторов"); //managerOperator = DBDataExtractor<User>.GetDataList(DBProvider.Client.GetUserList) == null ? new FullyObservableCollection<User>() : new FullyObservableCollection<User>(DBDataExtractor<User>.GetDataList(DBProvider.Client.GetUserList)); managerOperator = DBDataExtractor <User> .GetDataList(DBProvider.Client.GetUserList); OnDataCatalogMessage("Загружаю контакты"); ContactPerson = DBDataExtractor <ContactPerson> .GetDataList(DBProvider.Client.GetContactPersonList); /* * ToGoCustomers = DBDataExtractor<OrderCustomer>.GetDataList(DBProvider.Client.GetOrderCustomerList); * ToGoCustomersAddresses = new FullyObservableCollection<OrderCustomerAddress>(); * foreach (var cust in ToGoCustomers) * { * foreach (var addr in cust.Addresses) * { * ToGoCustomersAddresses.Add(addr); * } * } */ OnDataCatalogMessage("Загружаю наклейки"); //ItemLabelsInfo = DBDataExtractor<ItemLabelInfo>.GetDataList(DBProvider.Client.GetItemLabelInfoList) == null ? new FullyObservableCollection<ItemLabelInfo>() : new FullyObservableCollection<ItemLabelInfo>(DBDataExtractor<ItemLabelInfo>.GetDataList(DBProvider.Client.GetItemLabelInfoList)); ItemLabelsInfo = DBDataExtractor <ItemLabelInfo> .GetDataList(DBProvider.Client.GetItemLabelInfoList); DishLogicGroup = DBDataExtractor <DishLogicGroup> .GetDataList(DBProvider.Client.GetDishLogicGroupsList); DishKitchenGroup = DBDataExtractor <DishKitchenGroup> .GetDataList(DBProvider.Client.GetDishKitсhenGroupsList); OnDataCatalogMessage("Загружаю авиакомпании"); PaymentGroups = DBDataExtractor <PaymentGroup> .GetDataList(DBProvider.Client.GetPaymentGroupList); Payments = DBDataExtractor <Payment> .GetDataList(DBProvider.Client.GetPaymentList); foreach (var a in Payments) { if (a.PaymentGroupId != 0) { a.PaymentGroup = PaymentGroups.SingleOrDefault(b => b.Id == a.PaymentGroupId); } PaymentsSourceCache.AddOrUpdate(a); } Discounts = DBDataExtractor <Discount> .GetDataList(DBProvider.Client.GetDiscountList); AllAirCompanies = new FullyObservableCollection <AirCompany>(DBDataExtractor <AirCompany> .GetDataList(DBProvider.Client.GetAirCompanyList) //.Where(a => !DBProvider.SharAirs.Contains(a.Id) || ((Authorization.CurentUser != null) && ((Authorization.CurentUser.UserName == "sh.user") || (Authorization.IsDirector)))) .OrderBy(a => a.Name)); foreach (var a in AllAirCompanies) { if (a.PaymentId != null) { a.PaymentType = Payments.SingleOrDefault(b => b.Id == a.PaymentId); } if (a.DiscountId != null) { a.DiscountType = Discounts.SingleOrDefault(b => b.Id == a.DiscountId); } } AirCompanies = new FullyObservableCollection <AirCompany>(AllAirCompanies.Where(a => a.IsActive && (!DBProvider.SharAirs.Contains(a.Id) || ((Authorization.CurentUser != null) && ((Authorization.CurentUser.UserName == "sh.user") || (Authorization.IsDirector)))))); //AirCompanies = DBDataExtractor<AirCompany>.GetDataList(DBProvider.Client.GetAirCompanyList); //DeliveryPlaces = DBDataExtractor<DeliveryPlace>.GetDataList(DBProvider.Client.GetDeliveryPlaceList) == null ? new FullyObservableCollection<DeliveryPlace>() : new FullyObservableCollection<DeliveryPlace>(DBDataExtractor<DeliveryPlace>.GetDataList(DBProvider.Client.GetDeliveryPlaceList)); DeliveryPlaces = DBDataExtractor <DeliveryPlace> .GetDataList(DBProvider.Client.GetDeliveryPlaceList); Drivers = DBDataExtractor <Driver> .GetDataList(DBProvider.Client.GetDriverList) == null ? new FullyObservableCollection <Driver>() : new FullyObservableCollection <Driver>(DBDataExtractor <Driver> .GetDataList(DBProvider.Client.GetDriverList)); mDiscounts = DBDataExtractor <Discount> .GetDataList(DBProvider.Client.GetDiscountList) == null ? new FullyObservableCollection <Discount>() : new FullyObservableCollection <Discount>(DBDataExtractor <Discount> .GetDataList(DBProvider.Client.GetDiscountList)); OnDataCatalogMessage("Загружаю блюда"); Dishes = DBDataExtractor <Dish> .GetDataList(DBProvider.Client.GetDishList); foreach (var d in Dishes) { if (d.DishKitсhenGroupId > 0) { try { d.DishKitсhenGroup = DishKitchenGroup.Single(a => a.Id == d.DishKitсhenGroupId); } catch { } } if (d.DishLogicGroupId > 0) { try { d.DishLogicGroup = DishLogicGroup.Single(a => a.Id == d.DishLogicGroupId); } catch { } } d.LabelsCount = ItemLabelsInfo.Where(a => a.ParenItemId == d.Id).Count(); } OnDataCatalogMessage("Загружаю cписок клиентов"); marketingChannels = DBDataExtractor <MarketingChannel> .GetDataList(DBProvider.Client.GetMarketingChannelList); ItemLabelsInfo.ItemPropertyChanged += ItemLabelsInfo_ItemPropertyChanged; RefreshDynamicData(); _logger.Debug("DataCatalogsFill end"); } catch (Exception e) { _logger.Debug($"DataCatalogsFill error {e.Message}"); MainClass.SetNeedExit("Ошибка загрузки справочников " + e.Message); } /* * foreach (var d in DBDataExtractor<Dish>.GetDataList(DBProvider.Client.GetDishList) == null ? new FullyObservableCollection<Dish>() : new FullyObservableCollection<Dish>(DBDataExtractor<Dish>.GetDataList(DBProvider.Client.GetDishList))) * { * dishes.Add(d); * } */ }