/// <summary> /// Executes get stores by employee request. /// </summary> /// <param name="request">The service request.</param> /// <returns>The response containing accessible stores of this employee.</returns> private static EntityDataServiceResponse <OrgUnit> GetEmployeeStoresFromAddressBook(GetEmployeeStoresFromAddressBookRealtimeRequest request) { var dataRequest = new GetEmployeeStoresFromAddressBookDataRequest(request.QueryResultSettings); EntityDataServiceResponse <OrgUnit> response = request.RequestContext.Execute <EntityDataServiceResponse <OrgUnit> >(dataRequest); return(response); }
private static void OnGetCartsExecuted(GetCartsDataRequest request, EntityDataServiceResponse <SalesTransaction> response) { // In order to know customer id associated with the cart it needs to be loaded first, therefore permission check happens after execute. var checkAccessRequest = new CheckAccessToCartServiceRequest(response.PagedEntityCollection.Results); request.RequestContext.Execute <NullResponse>(checkAccessRequest); }
private static PagedResult <Transaction> SearchJournalTransactionsLocally(TransactionSearchCriteria criteria, QueryResultSettings settings, RequestContext context) { var searchTransactionsDataRequest = new SearchJournalTransactionsDataRequest(criteria, settings); EntityDataServiceResponse <Transaction> searchJournalTransactions = context.Runtime .Execute <EntityDataServiceResponse <Transaction> >(searchTransactionsDataRequest, context); return(searchJournalTransactions.PagedEntityCollection); }
/// <summary> /// Round for channel payment method. /// </summary> /// <param name="request">Service request.</param> /// <returns>Rounded value.</returns> private GetRoundedValueServiceResponse GetPaymentRoundedValue(GetPaymentRoundedValueServiceRequest request) { GetChannelTenderTypesDataRequest dataServiceRequest = new GetChannelTenderTypesDataRequest(request.RequestContext.GetPrincipal().ChannelId, QueryResultSettings.AllRecords); EntityDataServiceResponse <TenderType> response = request.RequestContext.Execute <EntityDataServiceResponse <TenderType> >(dataServiceRequest); TenderType tenderType = response.PagedEntityCollection.Results.SingleOrDefault(channelTenderType => string.Equals(channelTenderType.TenderTypeId, request.TenderTypeId, StringComparison.OrdinalIgnoreCase)); RoundingMethod roundingMethod = tenderType.RoundingMethod; if (roundingMethod == RoundingMethod.None) { return(new GetRoundedValueServiceResponse(request.Value)); } decimal currencyUnit = tenderType.RoundOff; if (currencyUnit == decimal.Zero) { currencyUnit = Rounding.DefaultRoundingValue; } decimal roundedValue; if (request.IsChange) { // For change rounding up/down should be applied in opposite direction. if (roundingMethod == RoundingMethod.Down) { roundingMethod = RoundingMethod.Up; } else if (roundingMethod == RoundingMethod.Up) { roundingMethod = RoundingMethod.Down; } } // Using absolute value so payment and refund is rounded same way when rounding up or down. decimal absoluteAmount = Math.Abs(request.Value); roundedValue = Rounding.RoundToUnit(absoluteAmount, currencyUnit, roundingMethod); if (request.Value < 0) { // Revert sign back to original. roundedValue = decimal.Negate(roundedValue); } return(new GetRoundedValueServiceResponse(roundedValue)); }
/// <summary> /// Retrieves the cash tender type identifier. /// </summary> /// <param name="context">The request context.</param> /// <returns>The tender type identifier for cash tender type.</returns> private static string GetCashTenderTypeIdentifier(RequestContext context) { string cashTenderTypeId = null; int payCashOperationId = (int)RetailOperation.PayCash; var dataServiceRequest = new GetChannelTenderTypesDataRequest(context.GetPrincipal().ChannelId, QueryResultSettings.AllRecords); EntityDataServiceResponse <TenderType> dataServiceResponse = context.Execute <EntityDataServiceResponse <TenderType> >(dataServiceRequest); ReadOnlyCollection <TenderType> tenderTypes = dataServiceResponse.PagedEntityCollection.Results; if (tenderTypes != null) { cashTenderTypeId = tenderTypes.Where(t => t.OperationId == payCashOperationId).Select(t => t.TenderTypeId).FirstOrDefault(); } return(cashTenderTypeId != null ? cashTenderTypeId : "-1"); // Defaulting to -1, same as EPOS }
/// <summary> /// Gets the loyalty card status including the loyalty groups and the reward points status. /// </summary> /// <param name="request">The request containing the card number.</param> /// <returns>The response containing the loyalty card status.</returns> private static GetLoyaltyCardStatusServiceResponse GetLoyaltyCardStatus(GetLoyaltyCardStatusServiceRequest request) { // Get loyalty card basic information var getLoyaltyCardDataRequest = new GetLoyaltyCardDataRequest(request.LoyaltyCardNumber); LoyaltyCard loyaltyCard = request.RequestContext.Execute <SingleEntityDataServiceResponse <LoyaltyCard> >(getLoyaltyCardDataRequest).Entity; if (loyaltyCard == null) { return(new GetLoyaltyCardStatusServiceResponse()); } var validateCustomerAccountRequest = new GetValidatedCustomerAccountNumberServiceRequest(loyaltyCard.CustomerAccount, throwOnValidationFailure: true); request.RequestContext.Execute <GetValidatedCustomerAccountNumberServiceResponse>(validateCustomerAccountRequest); // Get loyalty groups and loyalty tiers DateTimeOffset channelDateTime = request.RequestContext.GetNowInChannelTimeZone(); var getLoyaltyGroupsAndTiersDataRequest = new GetLoyaltyGroupsAndTiersDataRequest(request.LoyaltyCardNumber, request.RetrieveRewardPointStatus); getLoyaltyGroupsAndTiersDataRequest.QueryResultSettings = QueryResultSettings.AllRecords; loyaltyCard.LoyaltyGroups = request.RequestContext.Execute <EntityDataServiceResponse <LoyaltyGroup> >(getLoyaltyGroupsAndTiersDataRequest).PagedEntityCollection.Results; // Get reward points status if (request.RetrieveRewardPointStatus) { var serviceRequest = new GetLoyaltyCardRewardPointsStatusRealtimeRequest( channelDateTime, request.LoyaltyCardNumber, excludeBlocked: false, excludeNoTender: false, includeRelatedCardsForContactTender: false, includeNonRedeemablePoints: false, includeActivePointsOnly: false); EntityDataServiceResponse <LoyaltyCard> serviceResponse = request.RequestContext.Execute <EntityDataServiceResponse <LoyaltyCard> >(serviceRequest); LoyaltyCard loyaltyCardWithPoints = serviceResponse.PagedEntityCollection.FirstOrDefault(); if (loyaltyCardWithPoints != null) { loyaltyCard.RewardPoints = loyaltyCardWithPoints.RewardPoints; } } var response = new GetLoyaltyCardStatusServiceResponse(loyaltyCard); return(response); }
/// <summary> /// Gets required tender declaration amounts of a shift per tender type. /// </summary> /// <param name="context">The request context.</param> /// <param name="shiftTerminalId">The shift terminal identifier.</param> /// <param name="shiftId">The shift identifier.</param> /// <returns>The dictionary of shift tender lines where key is tender type identifier, and value is shift tender line object.</returns> private static Dictionary <string, ShiftTenderLine> GetShiftRequiredAmountsPerTender(RequestContext context, string shiftTerminalId, string shiftId) { var dataServiceRequest = new GetShiftRequiredAmountsPerTenderDataRequest(shiftTerminalId, shiftId); EntityDataServiceResponse <ShiftTenderLine> dataServiceResponse = context.Runtime.Execute <EntityDataServiceResponse <ShiftTenderLine> >(dataServiceRequest, context); ReadOnlyCollection <ShiftTenderLine> shiftTenderLines = dataServiceResponse.PagedEntityCollection.Results; if (shiftTenderLines == null) { throw new DataValidationException( DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ObjectNotFound, string.Format("No tender line was found on the terminal {0} for shift {1}.", shiftTerminalId, shiftId)); } var shiftTenderLineDict = shiftTenderLines.ToDictionary(s => s.TenderTypeId, s => s); return(shiftTenderLineDict); }
/// <summary> /// Gets the tender types for the channel. /// </summary> /// <param name="context">The request context.</param> /// <returns>The dictionary of tender types where key is tender type identifier, and value is tender type object.</returns> private static Dictionary <string, TenderType> GetChannelTenderTypes(RequestContext context) { long channelId = context.GetPrincipal().ChannelId; var dataServiceRequest = new GetChannelTenderTypesDataRequest(channelId, QueryResultSettings.AllRecords); EntityDataServiceResponse <TenderType> dataServiceResponse = context.Runtime.Execute <EntityDataServiceResponse <TenderType> >(dataServiceRequest, context); ReadOnlyCollection <TenderType> tenderTypes = dataServiceResponse.PagedEntityCollection.Results; if (tenderTypes == null) { throw new DataValidationException( DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ObjectNotFound, string.Format("The tender types of channel {0} was not found.", channelId)); } var tenderTypeDict = tenderTypes.ToDictionary(t => t.TenderTypeId, t => t); return(tenderTypeDict); }
/// <summary> /// Gets the accessible stores of the current employee. /// </summary> /// <param name="request">Instance of <see cref="GetStoresByEmployeeServiceRequest"/>.</param> /// <returns>Instance of <see cref="EntityDataServiceResponse{OrgUnit}"/>.</returns> private static EntityDataServiceResponse <OrgUnit> GetStoresByEmployee(GetStoresByEmployeeServiceRequest request) { ThrowIf.Null(request.RequestContext, "request.RequestContext"); EntityDataServiceResponse <OrgUnit> response = null; if (request.RequestContext.Runtime.Configuration.IsMasterDatabaseConnectionString) { // If connected to online, we make a RTS call for retrieving all accessible org units. var serviceRequest = new GetEmployeeStoresFromAddressBookRealtimeRequest(request.QueryResultSettings); response = request.RequestContext.Execute <EntityDataServiceResponse <OrgUnit> >(serviceRequest); } else { var dataRequest = new GetEmployeeStoresFromAddressBookDataRequest(request.QueryResultSettings); response = request.RequestContext.Execute <EntityDataServiceResponse <OrgUnit> >(dataRequest); } return(response); }
/// <summary> /// Gets the delivery preferences applicable for each sales line individually and combined. /// </summary> /// <param name="request">The request.</param> /// <returns>The delivery preferences applicable to the request.</returns> private static GetDeliveryPreferencesServiceResponse GetDeliveryPreferences(GetDeliveryPreferencesServiceRequest request) { ThrowIf.Null(request, "request"); ThrowIf.Null(request.RequestContext, "request.RequestContext"); ThrowIf.Null(request.CartId, "request.CartId"); // Try to load the transaction GetCartsDataRequest getCartDataRequest = new GetCartsDataRequest(new CartSearchCriteria { CartId = request.CartId }, QueryResultSettings.SingleRecord); SalesTransaction salesTransaction = request.RequestContext.Runtime.Execute <EntityDataServiceResponse <SalesTransaction> >(getCartDataRequest, request.RequestContext).PagedEntityCollection.SingleOrDefault(); if (salesTransaction.ActiveSalesLines == null || !salesTransaction.ActiveSalesLines.Any()) { return(new GetDeliveryPreferencesServiceResponse(new CartDeliveryPreferences())); } var dataServiceRequest = new GetDeliveryPreferencesDataRequest(salesTransaction.ActiveSalesLines); dataServiceRequest.QueryResultSettings = QueryResultSettings.AllRecords; EntityDataServiceResponse <CartLineDeliveryPreference> dataServiceResponse = request.RequestContext.Runtime.Execute <EntityDataServiceResponse <CartLineDeliveryPreference> >(dataServiceRequest, request.RequestContext); ReadOnlyCollection <CartLineDeliveryPreference> salesLineDeliveryPreferences = dataServiceResponse.PagedEntityCollection.Results; IEnumerable <string> salesLineIdsWithoutDeliveryPreferences = salesLineDeliveryPreferences.Where(sl => (sl.DeliveryPreferenceTypes == null || !sl.DeliveryPreferenceTypes.Any())).Select(sl => sl.LineId); if (salesLineIdsWithoutDeliveryPreferences.Any()) { string lineIds = string.Join(" ", salesLineIdsWithoutDeliveryPreferences); var message = string.Format("No delivery preferences could be retrieved for the sales line ids : {0}.", lineIds); throw new ConfigurationException(ConfigurationErrors.Microsoft_Dynamics_Commerce_Runtime_UnableToFindDeliveryPreferences, message); } IEnumerable <DeliveryPreferenceType> headerLevelDeliveryPreferences = GetHeaderLevelDeliveryPreferences(salesLineDeliveryPreferences); CartDeliveryPreferences cartDeliveryPreferences = new CartDeliveryPreferences(headerLevelDeliveryPreferences, salesLineDeliveryPreferences); return(new GetDeliveryPreferencesServiceResponse(cartDeliveryPreferences)); }