예제 #1
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));
            }
예제 #2
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));
            }