/// <summary> /// Gets the tender detail object from the client. /// </summary> /// <param name="context">The request context.</param> /// <param name="tenderDetail">The tender detail object from client.</param> /// <returns>The tender detail object to be saved on channel database.</returns> internal static TenderDetail ConvertToTenderDetail(RequestContext context, TenderDetail tenderDetail) { var tender = new TenderDetail { BankBagNumber = tenderDetail.BankBagNumber, // bankbag number TenderTypeId = tenderDetail.TenderTypeId, // tender type identifier Amount = tenderDetail.Amount // amount in channel currency }; string channelCurrency = context.GetChannelConfiguration().Currency; string foreignCurrency = string.IsNullOrWhiteSpace(tenderDetail.ForeignCurrency) ? channelCurrency : tenderDetail.ForeignCurrency; // Check if the foreign currency of the transaction is in channel currency if (foreignCurrency.Equals(channelCurrency, StringComparison.OrdinalIgnoreCase)) { tender.ForeignCurrency = channelCurrency; // foreign currency code is same as store currency code tender.AmountInForeignCurrency = tenderDetail.Amount; // foreign amount is same as store amount tender.ForeignCurrencyExchangeRate = 1m; // foreign to channel currency exchange rate is 1 } else { tender.ForeignCurrency = foreignCurrency; // foreign currency code tender.AmountInForeignCurrency = tenderDetail.AmountInForeignCurrency; // foreign amount tender.ForeignCurrencyExchangeRate = tenderDetail.ForeignCurrencyExchangeRate; // foreign to channel 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, tender.AmountInForeignCurrency, tender.ForeignCurrency); tender.AmountInCompanyCurrency = companyCurrencyValues.Item1; // amount MST tender.CompanyCurrencyExchangeRate = companyCurrencyValues.Item2; // exchange rate MST return(tender); }
/// <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); }