private GetReceiptResponse GetReceiptForNonSalesTransaction(string transactionId, ReceiptRetrievalCriteria criteria)
            {
                NonSalesTransaction nonSalesTransaction = null;
                long shiftId = criteria.ShiftId.GetValueOrDefault(0);

                switch (criteria.ReceiptType)
                {
                case ReceiptType.FloatEntry:
                    nonSalesTransaction = this.GetNonSaleTransaction(transactionId, TransactionType.FloatEntry, shiftId, criteria.ShiftTerminalId);
                    break;

                case ReceiptType.StartingAmount:
                    nonSalesTransaction = this.GetNonSaleTransaction(transactionId, TransactionType.StartingAmount, shiftId, criteria.ShiftTerminalId);
                    break;

                case ReceiptType.RemoveTender:
                    nonSalesTransaction = this.GetNonSaleTransaction(transactionId, TransactionType.RemoveTender, shiftId, criteria.ShiftTerminalId);
                    break;
                }

                var getReceiptServiceRequest  = new GetReceiptServiceRequest(nonSalesTransaction, criteria.ReceiptType, criteria.IsCopy, criteria.IsPreview, criteria.HardwareProfileId);
                var getReceiptServiceResponse = this.Context.Execute <GetReceiptServiceResponse>(getReceiptServiceRequest);

                return(new GetReceiptResponse(getReceiptServiceResponse.Receipts));
            }
Example #2
0
            /// <summary>
            /// Fills the data for non sales tender operation.
            /// </summary>
            /// <param name="transactionId">Transaction identifier.</param>
            /// <param name="transaction">Non sale tender transaction.</param>
            /// <param name="paymentTable">Data table for Payments.</param>
            /// <param name="context">Request context.</param>
            private void FillPaymentDataTable(string transactionId, NonSalesTransaction transaction, DataTable paymentTable, RequestContext context)
            {
                ThrowIf.Null(transaction, "transaction");
                ThrowIf.Null(paymentTable, "paymentTable");

                int     lineNumber     = 1; // Line number 1 for cash tender line
                bool    isRemoveTender = transaction.TransactionType == TransactionType.RemoveTender;
                DataRow row            = paymentTable.NewRow();

                row[RetailTransactionTableSchema.TransactionIdColumn]          = transactionId;
                row[RetailTransactionPaymentSchema.LineNumColumn]              = lineNumber;
                row[RetailTransactionPaymentSchema.ForeignCurrencyTableColumn] = transaction.ForeignCurrency;
                row[RetailTransactionPaymentSchema.TenderTypeTableColumn]      = transaction.TenderTypeId;
                row[RetailTransactionPaymentSchema.DataAreaIdColumn]           = context.GetChannelConfiguration().InventLocationDataAreaId;
                row[RetailTransactionTableSchema.StaffIdColumn]                            = transaction.StaffId;
                row[RetailTransactionTableSchema.TerminalColumn]                           = string.IsNullOrWhiteSpace(transaction.TerminalId) ? context.GetTerminal().TerminalId : transaction.TerminalId;
                row[RetailTransactionTableSchema.StoreColumn]                              = transaction.StoreId;
                row[RetailTransactionPaymentSchema.AmountTenderedColumn]                   = isRemoveTender ? decimal.Negate(transaction.Amount) : transaction.Amount;
                row[RetailTransactionPaymentSchema.ForeignCurrencyAmountColumn]            = isRemoveTender ? decimal.Negate(transaction.AmountInForeignCurrency) : transaction.AmountInForeignCurrency;
                row[RetailTransactionPaymentSchema.ForeignCurrencyExchangeRateTableColumn] = transaction.ForeignCurrencyExchangeRate;
                row[RetailTransactionPaymentSchema.CompanyCurrencyAmountColumn]            = isRemoveTender ? decimal.Negate(transaction.AmountInCompanyCurrency) : transaction.AmountInCompanyCurrency;
                row[RetailTransactionPaymentSchema.CompanyCurrencyExchangeRateColumn]      = transaction.CompanyCurrencyExchangeRate;

                paymentTable.Rows.Add(row);

                lineNumber = 2; // Line number 2 for balance tender line

                // Add tender removal type for every non sale tender operation.
                DataRow tenderRemovalRow = this.FillTenderRemovalPaymentType(context.GetChannelConfiguration().InventLocationDataAreaId, transactionId, lineNumber, transaction, paymentTable, context);

                paymentTable.Rows.Add(tenderRemovalRow);
            }
Example #3
0
            /// <summary>
            /// Invoke the method to get non sale tender transaction list for the given non sale tender type.
            /// </summary>
            /// <param name="request">Request for non sale tender service.</param>
            /// <returns>Returns the response for non sale tender operation get request.</returns>
            private static GetNonSaleTenderServiceResponse GetNonSaleTenderTransactions(GetNonSaleTenderServiceRequest request)
            {
                NonSalesTransaction tenderTransaction = StoreOperationServiceHelper.ConvertToNonSalesTenderTransaction(request.RequestContext, request.ShiftId, request.ShiftTerminalId, request.TransactionType);
                var getCurrentShiftNonSalesTransactionsdataServiceRequest = new GetCurrentShiftNonSalesTransactionsDataRequest(tenderTransaction, request.TransactionId);

                PagedResult <NonSalesTransaction> nonSaleOperationList = request.RequestContext.Runtime.Execute <EntityDataServiceResponse <NonSalesTransaction> >(getCurrentShiftNonSalesTransactionsdataServiceRequest, request.RequestContext).PagedEntityCollection;

                return(new GetNonSaleTenderServiceResponse(nonSaleOperationList));
            }
Example #4
0
            /// <summary>
            /// Save non sales transaction.
            /// </summary>
            /// <param name="request">Non sales transaction data service request.</param>
            /// <returns>A SingleEntityDataServiceResponse containing the saved NonSalesTransaction object.</returns>
            private SingleEntityDataServiceResponse <NonSalesTransaction> SaveNonSalesTransaction(SaveNonSalesTransactionDataRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.NonSalesTransaction, "request.NonSalesTransaction");

                var nonSalesTransaction = request.NonSalesTransaction;

                NonSalesTransaction savedTransaction = null;

                using (var transactionTable = new DataTable(RetailTransactionTableType))
                    using (var paymentTable = new DataTable(RetailTransactionPaymentTransTableType))
                        using (var reasonCodeTable = new DataTable(RetailTransactionInfoCodeTransTableType))
                        {
                            TransactionLog transaction = this.Convert(nonSalesTransaction);

                            RetailTransactionTableSchema.PopulateSchema(transactionTable);

                            TransactionLogDataManager.FillData(request.RequestContext, transaction, transactionTable);

                            var parameters = new ParameterSet();
                            parameters[DatabaseAccessor.ChannelIdVariableName] = request.RequestContext.GetPrincipal().ChannelId;
                            parameters["@tvp_Transaction"] = transactionTable;

                            if (!nonSalesTransaction.TransactionType.Equals(Microsoft.Dynamics.Commerce.Runtime.DataModel.TransactionType.OpenDrawer))
                            {
                                RetailTransactionPaymentSchema.PopulatePaymentSchema(paymentTable);
                                this.FillPaymentDataTable(nonSalesTransaction.Id, nonSalesTransaction, paymentTable, request.RequestContext);
                                parameters["@tvp_PaymentTrans"] = paymentTable;
                            }
                            else
                            {
                                RetailTransactionPaymentSchema.PopulateReasonCodeSchema(reasonCodeTable);                                    // Populate reason code schema
                                this.FillReasonCodeLines(transaction.Id, nonSalesTransaction, reasonCodeTable, -1m, request.RequestContext); // Fill captured reason code details
                                parameters["@tvp_ReasoncodeLine"] = reasonCodeTable;                                                         // Reason code parameter for [Open Drawer] store operation
                            }

                            int errorCode;
                            using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                            {
                                savedTransaction = sqlServerDatabaseContext.ExecuteStoredProcedure <NonSalesTransaction>(InsertNonSaleTenderSprocName, parameters, out errorCode).FirstOrDefault();
                            }

                            if (errorCode != (int)DatabaseErrorCodes.Success)
                            {
                                throw new StorageException(StorageErrors.Microsoft_Dynamics_Commerce_Runtime_CriticalStorageError, errorCode, "Unable to save non sale tender operation.");
                            }
                        }

                return(new SingleEntityDataServiceResponse <NonSalesTransaction>(savedTransaction));
            }
            /// <summary>
            /// Gets the object of non sales tender operation.
            /// </summary>
            /// <param name="context">The request context.</param>
            /// <param name="shiftId">The shift identifier.</param>
            /// <param name="shiftTerminalId">The shift terminal identifier.</param>
            /// <param name="tenderType">The non sale tender type.</param>
            /// <returns>The non sales tender operation object.</returns>
            internal static NonSalesTransaction ConvertToNonSalesTenderTransaction(RequestContext context, string shiftId, string shiftTerminalId, TransactionType tenderType)
            {
                var transaction = new NonSalesTransaction
                {
                    ShiftId         = shiftId,
                    TransactionType = tenderType,
                    TenderTypeId    = StoreOperationServiceHelper.GetCashTenderTypeIdentifier(context), // Default it to cash.
                    StoreId         = context.GetOrgUnit().OrgUnitNumber,
                    StaffId         = context.GetPrincipal().UserId,
                    TerminalId      = context.GetTerminal().TerminalId,
                    ShiftTerminalId = string.IsNullOrWhiteSpace(shiftTerminalId) ? context.GetPrincipal().ShiftTerminalId : shiftTerminalId
                };

                return(transaction);
            }
Example #6
0
            /// <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));
            }
            /// <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);
            }
Example #8
0
            /// <summary>
            /// Converts from non sale tender operation type to transaction log.
            /// </summary>
            /// <param name="nonSalesTransaction">Non sale tender transaction.</param>
            /// <returns>Returns the transaction log entity.</returns>
            private TransactionLog Convert(NonSalesTransaction nonSalesTransaction)
            {
                ThrowIf.NullOrWhiteSpace(nonSalesTransaction.Id, "nonSalesTransaction.Id");

                var transaction = new TransactionLog();

                transaction.Id                          = nonSalesTransaction.Id;
                transaction.StoreId                     = nonSalesTransaction.StoreId;
                transaction.TransactionType             = (TransactionType)nonSalesTransaction.TransactionTypeValue;
                transaction.StaffId                     = nonSalesTransaction.StaffId;
                transaction.ShiftId                     = nonSalesTransaction.ShiftId;
                transaction.ShiftTerminalId             = nonSalesTransaction.ShiftTerminalId;
                transaction.TerminalId                  = nonSalesTransaction.TerminalId;
                transaction.Description                 = nonSalesTransaction.Description;
                transaction.ChannelCurrencyExchangeRate = nonSalesTransaction.ChannelCurrencyExchangeRate;
                transaction.ChannelCurrency             = nonSalesTransaction.ChannelCurrency;

                return(transaction);
            }
Example #9
0
            /// <summary>
            /// Saves the reason code line.
            /// </summary>
            /// <param name="transactionId">Transaction identifier.</param>
            /// <param name="transaction">The transaction.</param>
            /// <param name="reasonCodeTable">The reason code table.</param>
            /// <param name="parentLineNumber">The parent line number.</param>
            /// <param name="context">The request context.</param>
            private void FillReasonCodeLines(string transactionId, NonSalesTransaction transaction, DataTable reasonCodeTable, decimal parentLineNumber, RequestContext context)
            {
                ThrowIf.Null(transaction, "transaction");
                ThrowIf.Null(reasonCodeTable, "reasonCodeTable");

                int            lineNumber      = 1;
                DateTimeOffset transactionDate = context.GetNowInChannelTimeZone();

                foreach (ReasonCodeLine reasonCodeLine in transaction.ReasonCodeLines)
                {
                    DataRow row = reasonCodeTable.NewRow();
                    row[RetailTransactionPaymentSchema.TransactionIdColumn] = transactionId;
                    row[RetailTransactionPaymentSchema.TransDateColumn]     = transactionDate.Date;

                    // trans time is stored as seconds (integer) in the database
                    row[RetailTransactionPaymentSchema.TransTimeColumn]  = (int)transactionDate.TimeOfDay.TotalSeconds;
                    row[RetailTransactionPaymentSchema.LineNumColumn]    = lineNumber;
                    row[RetailTransactionPaymentSchema.DataAreaIdColumn] = context.GetChannelConfiguration().InventLocationDataAreaId;
                    row[RetailTransactionPaymentSchema.TypeColumn]       = (int)ReasonCodeLineType.NoSale;

                    row[RetailTransactionPaymentSchema.ReasonCodeIdColumn]      = StringDataHelper.TruncateString(reasonCodeLine.ReasonCodeId, 10);
                    row[RetailTransactionPaymentSchema.InformationColumn]       = StringDataHelper.TruncateString(reasonCodeLine.Information, 100);
                    row[RetailTransactionPaymentSchema.InformationAmountColumn] = reasonCodeLine.InformationAmount;
                    row[RetailTransactionPaymentSchema.StoreColumn]             = transaction.StoreId;
                    row[RetailTransactionPaymentSchema.TerminalColumn]          = transaction.TerminalId ?? string.Empty;
                    row[RetailTransactionPaymentSchema.StaffIdColumn]           = StringDataHelper.TruncateString(transaction.StaffId, 25);
                    row[RetailTransactionPaymentSchema.ItemTenderColumn]        = StringDataHelper.TruncateString(reasonCodeLine.ItemTender, 10);
                    row[RetailTransactionPaymentSchema.AmountColumn]            = reasonCodeLine.Amount;
                    row[RetailTransactionPaymentSchema.InputTypeColumn]         = (int)reasonCodeLine.InputType;
                    row[RetailTransactionPaymentSchema.SubReasonCodeIdColumn]   = StringDataHelper.TruncateString(reasonCodeLine.SubReasonCodeId, 10);
                    row[RetailTransactionPaymentSchema.StatementCodeColumn]     = StringDataHelper.TruncateString(reasonCodeLine.StatementCode, 25);
                    row[RetailTransactionPaymentSchema.SourceCodeColumn]        = StringDataHelper.TruncateString(reasonCodeLine.SourceCode, 20);
                    row[RetailTransactionPaymentSchema.SourceCode2Column]       = StringDataHelper.TruncateString(reasonCodeLine.SourceCode2, 20);
                    row[RetailTransactionPaymentSchema.SourceCode3Column]       = StringDataHelper.TruncateString(reasonCodeLine.SourceCode3, 20);
                    row[RetailTransactionPaymentSchema.ParentLineNumColumn]     = parentLineNumber;

                    reasonCodeTable.Rows.Add(row);
                    lineNumber++;
                }
            }
Example #10
0
            /// <summary>
            /// Fills the data for tender removal payment data table.
            /// </summary>
            /// <param name="dataAreaId">Data area identifier.</param>
            /// <param name="transactionId">Transaction identifier.</param>
            /// <param name="lineNumber">Payment row Line number.</param>
            /// <param name="transaction">Non sale tender transaction.</param>
            /// <param name="paymentTable">Data table for Payments.</param>
            /// <param name="context">Request context.</param>
            /// <returns>Returns the tender removal tender type data row.</returns>
            private DataRow FillTenderRemovalPaymentType(string dataAreaId, string transactionId, int lineNumber, NonSalesTransaction transaction, DataTable paymentTable, RequestContext context)
            {
                ThrowIf.Null(transaction, "transaction");
                ThrowIf.Null(paymentTable, "paymentTable");

                bool    isRemoveTender = transaction.TransactionType == TransactionType.RemoveTender;
                DataRow row            = paymentTable.NewRow();

                row[RetailTransactionTableSchema.DataAreaIdColumn]                         = dataAreaId;
                row[RetailTransactionTableSchema.TransactionIdColumn]                      = transactionId;
                row[RetailTransactionPaymentSchema.LineNumColumn]                          = lineNumber;
                row[RetailTransactionPaymentSchema.AmountTenderedColumn]                   = isRemoveTender ? transaction.Amount : decimal.Negate(transaction.Amount);
                row[RetailTransactionPaymentSchema.ForeignCurrencyAmountColumn]            = isRemoveTender ? transaction.AmountInForeignCurrency : decimal.Negate(transaction.AmountInForeignCurrency);
                row[RetailTransactionPaymentSchema.ForeignCurrencyExchangeRateTableColumn] = transaction.ForeignCurrencyExchangeRate;
                row[RetailTransactionPaymentSchema.CompanyCurrencyAmountColumn]            = isRemoveTender ? transaction.AmountInCompanyCurrency : decimal.Negate(transaction.AmountInCompanyCurrency);
                row[RetailTransactionPaymentSchema.CompanyCurrencyExchangeRateColumn]      = transaction.CompanyCurrencyExchangeRate;
                row[RetailTransactionPaymentSchema.ForeignCurrencyTableColumn]             = transaction.ForeignCurrency;
                row[RetailTransactionPaymentSchema.TenderTypeTableColumn]                  = this.GetTenderRemovalTypeIdentifier(context);
                row[RetailTransactionTableSchema.StaffIdColumn]  = transaction.StaffId;
                row[RetailTransactionTableSchema.TerminalColumn] = string.IsNullOrWhiteSpace(transaction.TerminalId) ? context.GetTerminal().TerminalId : transaction.TerminalId;
                row[RetailTransactionTableSchema.StoreColumn]    = transaction.StoreId;

                return(row);
            }
Example #11
0
 public Task <NonSalesTransaction> CreateNonSalesTransaction(NonSalesTransaction nonSalesTransaction)
 {
     return(Task.Run(() => Runtime.Client.StoreOperationsManager.Create(CommerceRuntimeManager.Runtime).SaveNonSaleTenderOperation(nonSalesTransaction)));
 }