public Location CommitChanges() { if (BusinessDomain.AppConfiguration.AutoGenerateLocationCodes && string.IsNullOrWhiteSpace(code)) { AutoGenerateCode(); } if (!string.IsNullOrEmpty(groupName) && groupId <= 1) { LocationsGroup g = GroupBase <LocationsGroup> .EnsureByPath(groupName, LocationsGroup.Cache); groupId = g.Id; } BusinessDomain.DataAccessProvider.AddUpdateLocation(this, BusinessDomain.AppConfiguration.DocumentNumbersPerLocation, OperationNumberingInfo.RECOMMENDED_NUMBERS_PER_LOCATION); cache.Set(this); return(this); }
public static void ReapplyOnLocationChanged <T> (Operation <T> operation, Action <string, Action> reapplyConfirmation, IListModel <PriceRule> allRules = null) where T : OperationDetail, new () { if (operation.Details.Count == 0) { return; } if (allRules == null) { allRules = GetAll(); } if (!allRules.Where(p => p.Enabled).SelectMany(r => r.Conditions).Any(c => { if (c.Error || c.Values == null || c.Values.Length <= 0 || c.Values [0] == null) { return(false); } switch (c.Type) { case ConditionType.Object: return((long)c.Values [0] == operation.LocationId); case ConditionType.ObjectGroup: string stringValue = (string)c.Values [0]; long longValue; LocationsGroup locationsGroup = long.TryParse(stringValue, NumberStyles.Any, CultureInfo.InvariantCulture, out longValue) ? LocationsGroup.Cache.GetById(longValue) : LocationsGroup.Cache.GetByCode(stringValue); if (locationsGroup == null) { return(false); } Location location = Location.Cache.GetById(operation.LocationId); if (location == null) { return(false); } return(locationsGroup.Id == location.GroupId); } return(false); })) { return; } reapplyConfirmation(Translator.GetString("You have changed the location. Would you like to reapply your price rules?"), () => { for (int i = operation.Details.Count - 1; i >= 0; i--) { if ((operation.Details [i].AppliedPriceRules & AppliedActions.PromotionalItem) == AppliedActions.PromotionalItem) { operation.RemoveDetail(i, false); } else { operation.Details [i].AppliedPriceRules = AppliedActions.None; } } ApplyBeforeOperationSaved(operation, null, false, allRules); }); }
public bool CheckApplicableToOperation <T> (Operation <T> operation) where T : OperationDetail { if (error) { return(false); } DateTime dateFrom; DateTime dateTo; double @from; double to; bool ret; string groupCode = null; long? intValue; switch (type) { case PriceRule.ConditionType.Partner: ret = operation.PartnerId == Convert.ToInt64(values [0]); break; case PriceRule.ConditionType.PartnerGroup: intValue = PriceRule.GetLongValue(formula); if (intValue != null) { PartnersGroup byId = PartnersGroup.Cache.GetById(intValue.Value); if (byId != null) { groupCode = byId.Code; } } if (groupCode == null) { groupCode = PriceRule.GetStringValue(formula); } Partner partner = Partner.Cache.GetById(operation.PartnerId); ret = PartnersGroup.Cache.GetById(partner.GroupId).Code.StartsWith(groupCode); break; case PriceRule.ConditionType.Object: ret = operation.LocationId == Convert.ToInt64(values [0]); break; case PriceRule.ConditionType.ObjectGroup: intValue = PriceRule.GetLongValue(formula); if (intValue != null) { LocationsGroup byId = LocationsGroup.Cache.GetById(intValue.Value); if (byId != null) { groupCode = byId.Code; } } if (groupCode == null) { groupCode = PriceRule.GetStringValue(formula); } Location location = Location.Cache.GetById(operation.LocationId); ret = LocationsGroup.Cache.GetById(location.GroupId).Code.StartsWith(groupCode); break; case PriceRule.ConditionType.User: ret = operation.UserId == Convert.ToInt64(values [0]); break; case PriceRule.ConditionType.UserGroup: intValue = PriceRule.GetLongValue(formula); if (intValue != null) { UsersGroup byId = UsersGroup.Cache.GetById(intValue.Value); if (byId != null) { groupCode = byId.Code; } } if (groupCode == null) { groupCode = PriceRule.GetStringValue(formula); } User user = User.Cache.GetById(operation.UserId); ret = UsersGroup.Cache.GetById(user.GroupId).Code.StartsWith(groupCode); break; case PriceRule.ConditionType.Time: GetConditionDateTimeInterval(formula, out dateFrom, out dateTo); DateTime now = BusinessDomain.Now; if (dateFrom.TimeOfDay < dateTo.TimeOfDay) { ret = dateFrom.TimeOfDay <= now.TimeOfDay && now.TimeOfDay <= dateTo.TimeOfDay; } else { ret = dateFrom.TimeOfDay <= now.TimeOfDay || now.TimeOfDay <= dateTo.TimeOfDay; } break; case PriceRule.ConditionType.Date: GetConditionDateTimeInterval(formula, out dateFrom, out dateTo); ret = dateFrom <= operation.Date && operation.Date <= dateTo; break; case PriceRule.ConditionType.DocumentSum: GetConditionNumericInterval(formula, out from, out to); ret = from <= operation.Total && operation.Total <= to; break; case PriceRule.ConditionType.TurnoverSum: GetConditionNumericInterval(formula, out from, out to); double turnover = Partner.GetTurnover(operation.PartnerId); ret = from <= turnover && turnover <= to; break; case PriceRule.ConditionType.PaymentSum: GetConditionNumericInterval(formula, out from, out to); double debt = Partner.GetDebt(operation.PartnerId); ret = from <= debt && debt <= to; break; case PriceRule.ConditionType.Weekdays: List <DayOfWeek> ruleWeekDays = GetRuleWeekDays(); ret = ruleWeekDays.Contains(operation.Date.DayOfWeek); break; case PriceRule.ConditionType.UnpaidDocumentsSum: GetConditionNumericInterval(formula, out from, out to); double sum = Partner.GetUnpaidAmountWithExpiredDueDate(operation.PartnerId, operation.Date); ret = from <= sum && sum <= to; break; case PriceRule.ConditionType.ContainsGood: intValue = Convert.ToInt64(values [0]); ret = operation.Details.Any(d => d.ItemId == intValue) || operation.AdditionalDetails.Any(d => d.ItemId == intValue); break; case PriceRule.ConditionType.GoodGroup: case PriceRule.ConditionType.ContainsGGroup: Dictionary <long, string> codes = new Dictionary <long, string> (); foreach (T detail in operation.Details) { AddGroupCode(codes, detail.ItemGroupId); } foreach (T additionalDetail in operation.AdditionalDetails) { AddGroupCode(codes, additionalDetail.ItemGroupId); } intValue = PriceRule.GetLongValue(formula); if (intValue != null) { ItemsGroup byId = ItemsGroup.Cache.GetById(intValue.Value); if (byId != null) { groupCode = byId.Code; } } if (groupCode == null) { groupCode = PriceRule.GetStringValue(formula); } ret = codes.Values.Any(c => c.StartsWith(groupCode)); break; case PriceRule.ConditionType.PaymentTypeUsed: List <BasePaymentType> paymentTypes = GetConditionPaymentTypes(); ret = operation.Payments.Any(payment => paymentTypes.Contains(payment.Type.BaseType)); break; case PriceRule.ConditionType.DatabaseUpdated: ret = BusinessDomain.GetDatabaseLastUpdate().AddMinutes(30) > DateTime.Now; break; default: return(true); } return(ret != IsException); }