/// <summary> /// Gets the object of non sales tender operation. /// </summary> /// <param name="context">The request context.</param> /// <param name="nonSaleTenderServiceRequest">The non-sale shift tender operation request.</param> /// <returns>The non sales tender operation object.</returns> internal static NonSalesTransaction ConvertToNonSalesTenderTransaction(RequestContext context, SaveNonSaleTenderServiceRequest nonSaleTenderServiceRequest) { string channelCurrency = context.GetChannelConfiguration().Currency; var transaction = new NonSalesTransaction { Id = nonSaleTenderServiceRequest.TransactionId, ShiftId = nonSaleTenderServiceRequest.ShiftId, ShiftTerminalId = string.IsNullOrWhiteSpace(nonSaleTenderServiceRequest.ShiftTerminalId) ? context.GetPrincipal().ShiftTerminalId : nonSaleTenderServiceRequest.ShiftTerminalId, Description = nonSaleTenderServiceRequest.Description, TransactionType = nonSaleTenderServiceRequest.TransactionType, TenderTypeId = StoreOperationServiceHelper.GetCashTenderTypeIdentifier(context), // Default it to cash. StoreId = context.GetOrgUnit().OrgUnitNumber, StaffId = context.GetPrincipal().UserId, TerminalId = context.GetTerminal().TerminalId, ChannelCurrencyExchangeRate = StoreOperationServiceHelper.GetExchangeRate(context), Amount = nonSaleTenderServiceRequest.Amount, // amount in store currency ForeignCurrency = string.IsNullOrWhiteSpace(nonSaleTenderServiceRequest.Currency) ? channelCurrency : nonSaleTenderServiceRequest.Currency, ChannelCurrency = context.GetChannelConfiguration().Currency // channel currency code }; // Retrieve the amount in foreign currency with the exchange rate between foreign and channel currency Tuple <decimal, decimal> foreignCurrencyValues = StoreOperationServiceHelper.GetForeignCurrencyValues(context, transaction.Amount, transaction.ForeignCurrency); transaction.AmountInForeignCurrency = foreignCurrencyValues.Item1; // foreign currency amount transaction.ForeignCurrencyExchangeRate = foreignCurrencyValues.Item2; // foreign currency exchange rate // Retrieve the amount in company currency with the exchange rate between foreign and company currency Tuple <decimal, decimal> companyCurrencyValues = StoreOperationServiceHelper.GetCompanyCurrencyValues(context, transaction.AmountInForeignCurrency, transaction.ForeignCurrency); transaction.AmountInCompanyCurrency = companyCurrencyValues.Item1; // amount MST transaction.CompanyCurrencyExchangeRate = companyCurrencyValues.Item2; // exchange rate MST if (nonSaleTenderServiceRequest.ReasonCodeLines != null && nonSaleTenderServiceRequest.ReasonCodeLines.Any()) { // Read reason code details from service request for open drawer operation transaction.ReasonCodeLines = new Collection <ReasonCodeLine>(); foreach (var reasonCodeLine in nonSaleTenderServiceRequest.ReasonCodeLines) { transaction.ReasonCodeLines.Add(reasonCodeLine); } } return(transaction); }
/// <summary> /// Invoke the method to save non sale tender type transactions. /// </summary> /// <param name="request">Request for non sale tender transactions.</param> /// <returns>Returns the non sale tender transactions.</returns> private static SaveNonSaleTenderServiceResponse SaveNonSaleTenderTransactions(SaveNonSaleTenderServiceRequest request) { NonSalesTransaction nonSalesTransaction = StoreOperationServiceHelper.ConvertToNonSalesTenderTransaction(request.RequestContext, request); // If the previously created tender transaction response did not get received due to network connection issue. // On client retry, check if it was already saved. If true, returns saved object. var getCurrentShiftNonSalesTransactionsdataServiceRequest = new GetCurrentShiftNonSalesTransactionsDataRequest(nonSalesTransaction, request.TransactionId); NonSalesTransaction savedNonSalesTransaction = request.RequestContext.Runtime.Execute <EntityDataServiceResponse <NonSalesTransaction> >(getCurrentShiftNonSalesTransactionsdataServiceRequest, request.RequestContext).PagedEntityCollection.FirstOrDefault(); if (savedNonSalesTransaction == null) { var saveNonSalesTransactionsdataServiceRequest = new SaveNonSalesTransactionDataRequest(nonSalesTransaction); savedNonSalesTransaction = request.RequestContext.Runtime.Execute <SingleEntityDataServiceResponse <NonSalesTransaction> >(saveNonSalesTransactionsdataServiceRequest, request.RequestContext).Entity; } return(new SaveNonSaleTenderServiceResponse(savedNonSalesTransaction)); }