private GetReceiptResponse GetReceiptForDropAndDeclarationTransaction(string transactionId, ReceiptRetrievalCriteria criteria)
            {
                DropAndDeclareTransaction dropAndDeclareTransaction = this.GetDropAndDeclareTransaction(transactionId);

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

                return(new GetReceiptResponse(getReceiptServiceResponse.Receipts));
            }
Пример #2
0
            /// <summary>
            /// Fill data to the data table for TenderDeclaration tender lines.
            /// </summary>
            /// <param name="transactionId">Transaction identifier.</param>
            /// <param name="transaction">Tender drop and declare transactions.</param>
            /// <param name="tenderDeclarationTable">Tender drop and declare data table.</param>
            /// <param name="context">Request context.</param>
            private void FillTenderDataTable(string transactionId, DropAndDeclareTransaction transaction, DataTable tenderDeclarationTable, RequestContext context)
            {
                ThrowIf.Null(transaction, "transaction");
                ThrowIf.Null(tenderDeclarationTable, "tenderDeclarationTable");

                int lineNumber = 1;

                foreach (TenderDetail tenderDetail in transaction.TenderDetails)
                {
                    bool isTenderDeclaration = transaction.TransactionType == TransactionType.TenderDeclaration;
                    bool isBankDrop          = transaction.TransactionType == TransactionType.BankDrop;
                    bool isSafeDrop          = transaction.TransactionType == TransactionType.SafeDrop;

                    DataRow row = tenderDeclarationTable.NewRow();
                    row[TransactionIDColumn]  = transactionId;
                    row[TenderTypeColumn]     = tenderDetail.TenderTypeId;
                    row[AmountTenderedColumn] = tenderDetail.Amount;
                    row[LineNumColumn]        = lineNumber;
                    row[QTYColumn]            = 1;
                    row[CurrencyColumn]       = tenderDetail.ForeignCurrency;
                    row[AmountCurColumn]      = tenderDetail.AmountInForeignCurrency;
                    row[ExchangeColumn]       = tenderDetail.ForeignCurrencyExchangeRate;
                    row[AmountMSTColumn]      = tenderDetail.AmountInCompanyCurrency;
                    row[ExchangeMSTColumn]    = tenderDetail.CompanyCurrencyExchangeRate;
                    row[StaffColumn]          = transaction.StaffId;
                    row[StoreColumn]          = transaction.StoreId;
                    row[TerminalColumn]       = transaction.TerminalId;
                    row[DataAreaIdColumn]     = context.GetChannelConfiguration().InventLocationDataAreaId; // transaction.DataAreaId should also be ok
                    row[TransTimeColumn]      = (int)DateTime.UtcNow.TimeOfDay.TotalSeconds;

                    if (isTenderDeclaration)
                    {
                        row[PosCurrencyColumn] = transaction.ChannelCurrency;
                    }
                    else if (isBankDrop)
                    {
                        row[TypeColumn]              = (int)transaction.TransactionType;
                        row[AmountCurPOSColumn]      = tenderDetail.AmountInForeignCurrency;
                        row[AmountTenderedPOSColumn] = tenderDetail.Amount;
                        row[AmountMSTPOSColumn]      = tenderDetail.AmountInCompanyCurrency;
                        row[StatusTypeColumn]        = 1; // Always to 1 by the POS
                        row[BankBagNumColumn]        = tenderDetail.BankBagNumber;
                    }
                    else if (isSafeDrop)
                    {
                        row[TypeColumn]              = (int)transaction.TransactionType;
                        row[AmountCurPOSColumn]      = tenderDetail.AmountInForeignCurrency;
                        row[AmountTenderedPOSColumn] = tenderDetail.Amount;
                        row[AmountMSTPOSColumn]      = tenderDetail.AmountInCompanyCurrency;
                        row[StatusTypeColumn]        = 1; // Always to 1 by the POS
                    }

                    tenderDeclarationTable.Rows.Add(row);
                    lineNumber++;
                }
            }
            /// <summary>
            /// Get the drop and declare tender transaction.
            /// </summary>
            /// <param name="transactionId">The transaction identifier.</param>
            /// <returns>The drop and declare tender transaction.</returns>
            private DropAndDeclareTransaction GetDropAndDeclareTransaction(string transactionId)
            {
                var getDropAndDeclareTransactionDataRequest = new GetDropAndDeclareTransactionDataRequest(transactionId, QueryResultSettings.SingleRecord);
                DropAndDeclareTransaction transaction       = this.Context.Runtime.Execute <EntityDataServiceResponse <DropAndDeclareTransaction> >(getDropAndDeclareTransactionDataRequest, this.Context).PagedEntityCollection.FirstOrDefault();

                var getDropAndDeclareTransactionTenderDetailsDataRequest = new GetDropAndDeclareTransactionTenderDetailsDataRequest(transactionId, QueryResultSettings.AllRecords);
                PagedResult <TenderDetail> tenderDetails = this.Context.Runtime.Execute <EntityDataServiceResponse <TenderDetail> >(getDropAndDeclareTransactionTenderDetailsDataRequest, this.Context).PagedEntityCollection;

                transaction.TenderDetails = tenderDetails.Results;
                return(transaction);
            }
Пример #4
0
            /// <summary>
            /// Converts from non sale tender operation type to transaction log.
            /// </summary>
            /// <param name="tenderTransaction">Non sale tender transaction.</param>
            /// <returns>Returns the transaction log entity.</returns>
            private TransactionLog Convert(DropAndDeclareTransaction tenderTransaction)
            {
                ThrowIf.NullOrWhiteSpace(tenderTransaction.Id, "tenderTransaction.Id");

                var transaction = new TransactionLog();

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

                return(transaction);
            }
Пример #5
0
            /// <summary>
            /// Saves the reason code line for [Tender Declaration] store operation.
            /// </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, DropAndDeclareTransaction 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[TransactionIDColumn] = transactionId;
                    row[TransDateColumn]     = transactionDate.Date;

                    // trans time is stored as seconds (integer) in the database
                    row[TransTimeColumn]         = (int)transactionDate.TimeOfDay.TotalSeconds;
                    row[LineNumColumn]           = lineNumber;
                    row[DataAreaIdColumn]        = context.GetChannelConfiguration().InventLocationDataAreaId;
                    row[TypeColumn]              = (int)reasonCodeLine.LineType;
                    row[ReasonCodeIdColumn]      = StringDataHelper.TruncateString(reasonCodeLine.ReasonCodeId, 10);
                    row[InformationColumn]       = StringDataHelper.TruncateString(reasonCodeLine.Information, 100);
                    row[InformationAmountColumn] = reasonCodeLine.InformationAmount;
                    row[StoreColumn]             = transaction.StoreId;
                    row[TerminalColumn]          = transaction.TerminalId ?? string.Empty;
                    row[StaffColumn]             = StringDataHelper.TruncateString(transaction.StaffId, 25);
                    row[ItemTenderColumn]        = StringDataHelper.TruncateString(reasonCodeLine.ItemTender, 10);
                    row[AmountColumn]            = reasonCodeLine.Amount;
                    row[InputTypeColumn]         = (int)reasonCodeLine.InputType;
                    row[SubReasonCodeIdColumn]   = StringDataHelper.TruncateString(reasonCodeLine.SubReasonCodeId, 10);
                    row[StatementCodeColumn]     = StringDataHelper.TruncateString(reasonCodeLine.StatementCode, 25);
                    row[SourceCodeColumn]        = StringDataHelper.TruncateString(reasonCodeLine.SourceCode, 20);
                    row[SourceCode2Column]       = StringDataHelper.TruncateString(reasonCodeLine.SourceCode2, 20);
                    row[SourceCode3Column]       = StringDataHelper.TruncateString(reasonCodeLine.SourceCode3, 20);
                    row[ParentLineNumColumn]     = parentLineNumber;

                    reasonCodeTable.Rows.Add(row);
                    lineNumber++;
                }
            }
            /// <summary>
            /// Gets the object of tender drop and declare operation.
            /// </summary>
            /// <param name="request">The SaveDropAndDeclareServiceRequest object.</param>
            /// <returns>The tender drop and declare operation object.</returns>
            internal static DropAndDeclareTransaction ConvertTenderDropAndDeclareTransaction(SaveDropAndDeclareServiceRequest request)
            {
                RequestContext context     = request.RequestContext;
                var            transaction = new DropAndDeclareTransaction
                {
                    Id                          = request.TransactionId,
                    ShiftId                     = request.ShiftId,
                    ShiftTerminalId             = string.IsNullOrWhiteSpace(request.ShiftTerminalId) ? context.GetPrincipal().ShiftTerminalId : request.ShiftTerminalId,
                    TransactionType             = request.TransactionType,
                    ChannelCurrencyExchangeRate = StoreOperationServiceHelper.GetExchangeRate(context),
                    StoreId                     = context.GetOrgUnit().OrgUnitNumber,
                    StaffId                     = context.GetPrincipal().UserId,
                    TerminalId                  = context.GetTerminal().TerminalId,
                    ChannelCurrency             = context.GetChannelConfiguration().Currency, // channel currency code
                    Description                 = request.Description
                };

                transaction.TenderDetails = new Collection <TenderDetail>();
                foreach (var tenderDetail in request.TenderDetails)
                {
                    TenderDetail tender = ConvertToTenderDetail(context, tenderDetail);
                    transaction.TenderDetails.Add(tender);
                }

                if (request.ReasonCodeLines != null && request.ReasonCodeLines.Any())
                {
                    // Read reason code details from request for [Tender Declaration] store operation
                    transaction.ReasonCodeLines = new Collection <ReasonCodeLine>();
                    foreach (var reasonCodeLine in request.ReasonCodeLines)
                    {
                        transaction.ReasonCodeLines.Add(reasonCodeLine);
                    }
                }

                return(transaction);
            }
Пример #7
0
            /// <summary>
            /// Invoke the method to save drop and declare transactions.
            /// </summary>
            /// <param name="request">Request context.</param>
            /// <returns>Returns response for save drop and declare.</returns>
            private static SaveDropAndDeclareServiceResponse SaveDropAndDeclareTransactions(SaveDropAndDeclareServiceRequest request)
            {
                StoreOperationServiceHelper.ValidateTenderDeclarationCountingDifference(request);

                DropAndDeclareTransaction tenderDropAndDeclare = StoreOperationServiceHelper.ConvertTenderDropAndDeclareTransaction(request);

                // If the previously created drop 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 getDropAndDeclareTransactionDataRequest = new GetDropAndDeclareTransactionDataRequest(tenderDropAndDeclare.Id, QueryResultSettings.SingleRecord);
                DropAndDeclareTransaction transaction       = request.RequestContext.Runtime.Execute <EntityDataServiceResponse <DropAndDeclareTransaction> >(getDropAndDeclareTransactionDataRequest, request.RequestContext).PagedEntityCollection.FirstOrDefault();

                if (transaction != null)
                {
                    var getDropAndDeclareTransactionTenderDetailsDataRequest = new GetDropAndDeclareTransactionTenderDetailsDataRequest(tenderDropAndDeclare.Id, QueryResultSettings.AllRecords);
                    transaction.TenderDetails = request.RequestContext.Runtime.Execute <EntityDataServiceResponse <TenderDetail> >(getDropAndDeclareTransactionTenderDetailsDataRequest, request.RequestContext).PagedEntityCollection.Results;
                }
                else
                {
                    var saveDropAndDeclareTransactionDataRequest = new SaveDropAndDeclareTransactionDataRequest(tenderDropAndDeclare);
                    transaction = request.RequestContext.Runtime.Execute <SingleEntityDataServiceResponse <DropAndDeclareTransaction> >(saveDropAndDeclareTransactionDataRequest, request.RequestContext).Entity;
                }

                return(new SaveDropAndDeclareServiceResponse(transaction));
            }
Пример #8
0
 public Task <DropAndDeclareTransaction> CreateDropAndDeclareTransaction(DropAndDeclareTransaction dropAndDeclareTransaction)
 {
     return(Task.Run(() => Runtime.Client.StoreOperationsManager.Create(CommerceRuntimeManager.Runtime).SaveTenderDropAndDeclareOperation(dropAndDeclareTransaction)));
 }
Пример #9
0
            /// <summary>
            /// Save drop and declare transaction.
            /// </summary>
            /// <param name="request">Drop and declare transaction data service request.</param>
            /// <returns>A SingleEntityDataServiceResponse containing the saved DropAndDeclareTransaction object.</returns>
            private SingleEntityDataServiceResponse <DropAndDeclareTransaction> SaveDropAndDeclareTransaction(SaveDropAndDeclareTransactionDataRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.DropAndDeclareTransaction, "request.DropAndDeclareTransaction");

                DropAndDeclareTransaction dropAndDeclareTransaction = request.DropAndDeclareTransaction;

                Tuple <PagedResult <DropAndDeclareTransaction>, ReadOnlyCollection <TenderDetail> > results;

                using (var transactionTable = new DataTable(RetailTransactionTableType))
                    using (var tenderDeclarationTable = new DataTable(TenderDeclarationTransType))
                        using (var tenderDropTable = new DataTable(TenderDropTransType))
                            using (var reasonCodeTable = new DataTable(RetailTransactionInfoCodeTransTableType))
                            {
                                TransactionLog transaction = this.Convert(dropAndDeclareTransaction);

                                RetailTransactionTableSchema.PopulateSchema(transactionTable);
                                TenderDropAndDeclareTableSchema.PopulateTenderDeclarationSchema(tenderDeclarationTable);
                                TenderDropAndDeclareTableSchema.PopulateBankTenderDropSchema(tenderDropTable);
                                TenderDropAndDeclareTableSchema.PopulateReasonCodeSchema(reasonCodeTable);

                                // Fill the transaction header details.
                                TransactionLogDataManager.FillData(request.RequestContext, transaction, transactionTable);

                                // File the transaction line details.
                                if (dropAndDeclareTransaction.TransactionType == TransactionType.BankDrop ||
                                    dropAndDeclareTransaction.TransactionType == TransactionType.SafeDrop)
                                {
                                    this.FillTenderDataTable(transaction.Id, dropAndDeclareTransaction, tenderDropTable, request.RequestContext);
                                }
                                else if (dropAndDeclareTransaction.TransactionType == TransactionType.TenderDeclaration)
                                {
                                    this.FillTenderDataTable(transaction.Id, dropAndDeclareTransaction, tenderDeclarationTable, request.RequestContext);

                                    // Fill captured reason code details for [Tender Declaration] store operation
                                    this.FillReasonCodeLines(transaction.Id, dropAndDeclareTransaction, reasonCodeTable, -1m, request.RequestContext);
                                }

                                var parameters = new ParameterSet();

                                parameters[DatabaseAccessor.ChannelIdVariableName] = request.RequestContext.GetPrincipal().ChannelId;
                                parameters["@tvp_Transaction"]        = transactionTable;
                                parameters["@tvp_TenderDeclareTrans"] = tenderDeclarationTable;
                                parameters["@tvp_TenderDropTrans"]    = tenderDropTable;
                                parameters["@tvp_ReasoncodeLine"]     = reasonCodeTable;

                                int errorCode;
                                using (var sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                                {
                                    results = sqlServerDatabaseContext.ExecuteStoredProcedure <DropAndDeclareTransaction, TenderDetail>(InsertTenderDropAndDeclareSprocName, parameters, null, out errorCode);
                                }

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

                DropAndDeclareTransaction savedTransaction = results.Item1.FirstOrDefault();

                if (savedTransaction == null)
                {
                    throw new StorageException(StorageErrors.Microsoft_Dynamics_Commerce_Runtime_CriticalStorageError, "Unable to retrieve newly created tender drop and declare operation after save.");
                }

                savedTransaction.TenderDetails = results.Item2;

                return(new SingleEntityDataServiceResponse <DropAndDeclareTransaction>(savedTransaction));
            }