Esempio n. 1
0
            /// <summary>
            /// Calculate the totals, number of transactions happened in the current shift.
            /// </summary>
            /// <param name="context">Request context.</param>
            /// <param name="currentShift">Current shift object.</param>
            /// <param name="shiftTerminalId">Shift terminal Identifier.</param>
            /// <param name="shiftId">Shift identifier.</param>
            public static void Calculate(RequestContext context, Shift currentShift, string shiftTerminalId, long shiftId)
            {
                GetEndOfDayShiftDetailsDataRequest getEndOfDayShiftDetailsDataRequest = new GetEndOfDayShiftDetailsDataRequest(shiftTerminalId, shiftId, context.GetChannelConfiguration().PriceIncludesSalesTax);
                Shift endOfDayShiftDetails = context.Runtime.Execute <SingleEntityDataServiceResponse <Shift> >(getEndOfDayShiftDetailsDataRequest, context).Entity;

                // Sets the sales totals.
                SetShiftSalesTotals(currentShift, endOfDayShiftDetails);

                // Set the tender lines.
                SetShiftTenderLine(currentShift, endOfDayShiftDetails);

                // Set the account lines.
                SetShiftAccountLines(currentShift, endOfDayShiftDetails);

                // Calculates the shift counts.
                GetShiftTransactionsCountDataRequest getShiftTransactionCountsDataRequest = new GetShiftTransactionsCountDataRequest(shiftTerminalId, shiftId);
                Shift shiftCounts = context.Runtime.Execute <SingleEntityDataServiceResponse <Shift> >(getShiftTransactionCountsDataRequest, context).Entity;

                // Set the retail transaction counts.
                SetRetailTransactionCount(currentShift, shiftCounts);

                // Calculates the tender line tender amounts.
                GetShiftTenderedAmountDataRequest getShiftTenderedAmountDataRequest = new GetShiftTenderedAmountDataRequest(shiftTerminalId, shiftId, QueryResultSettings.AllRecords);
                var shiftTenderAmount = context.Runtime.Execute <EntityDataServiceResponse <ShiftTenderLine> >(getShiftTenderedAmountDataRequest, context).PagedEntityCollection.Results;

                // Set the tender line tender amounts.
                SetShiftTenderLineTenderAmounts(currentShift, shiftTenderAmount);
            }
            /// <summary>
            /// Loads the shift transactions data.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>A single entity data service response.</returns>
            private SingleEntityDataServiceResponse <Shift> GetEndOfDayshiftDetails(GetEndOfDayShiftDetailsDataRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.TerminalId, "request.TerminalId");

                ParameterSet parameters = new ParameterSet();

                parameters[DatabaseAccessor.ChannelIdVariableName] = request.RequestContext.GetPrincipal().ChannelId;
                parameters[TerminalIdVariableName]   = request.TerminalId;
                parameters[ShiftIdVariableName]      = request.ShiftId;
                parameters[TaxInclusiveVariableName] = Convert.ToInt32(request.IsTaxInclusive);

                Shift shift;

                using (SqlServerDatabaseContext sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                {
                    var result = sqlServerDatabaseContext.ExecuteStoredProcedure <Shift, ShiftTenderLine, ShiftAccountLine>(GetShiftSalesDataSprocName, parameters);
                    shift              = result.Item1.SingleOrDefault();
                    shift.TenderLines  = result.Item2;
                    shift.AccountLines = result.Item3;
                }

                return(new SingleEntityDataServiceResponse <Shift>(shift));
            }