Esempio n. 1
0
            /// <summary>
            /// Executes the resume shift workflow.
            /// </summary>
            /// <param name="request">The new shift request.</param>
            /// <returns>The resume shift response.</returns>
            protected override UseShiftResponse Process(UseShiftRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.Null(request.ShiftTerminalId, "request.ShiftTerminalId");

                GetCurrentTerminalIdDataRequest dataRequest = new GetCurrentTerminalIdDataRequest();

                request.TerminalId = this.Context.Execute <SingleEntityDataServiceResponse <string> >(dataRequest).Entity;

                GetShiftDataRequest getShiftDataRequest = new GetShiftDataRequest(request.ShiftTerminalId, request.ShiftId);
                Shift shift = this.Context.Execute <SingleEntityDataServiceResponse <Shift> >(getShiftDataRequest).Entity;

                if (shift == null)
                {
                    throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ObjectNotFound, "There is no shift with the given identifier.");
                }

                this.ValidateCanUseShift(request, shift);

                shift.CurrentStaffId    = this.Context.GetPrincipal().UserId;
                shift.CurrentTerminalId = request.TerminalId;
                shift.StatusDateTime    = this.Context.GetNowInChannelTimeZone();

                UpdateShiftStagingTableDataRequest dataServiceRequest = new UpdateShiftStagingTableDataRequest(shift);

                request.RequestContext.Runtime.Execute <NullResponse>(dataServiceRequest, this.Context);

                return(new UseShiftResponse(shift));
            }
Esempio n. 2
0
            /// <summary>
            /// Gets the shift.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>A single entity data service response.</returns>
            private SingleEntityDataServiceResponse <Shift> GetShift(GetShiftDataRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.NullOrWhiteSpace(request.TerminalId, "request.TerminalId");

                long channelId = request.RequestContext.GetPrincipal().ChannelId;

                // Loads shift.
                ShiftDataQueryCriteria criteria = new ShiftDataQueryCriteria();

                criteria.ChannelId           = channelId;
                criteria.TerminalId          = request.TerminalId;
                criteria.ShiftId             = request.ShiftId;
                criteria.SearchByTerminalId  = true;
                criteria.IncludeSharedShifts = true;

                GetShiftDataDataRequest dataServiceRequest = new GetShiftDataDataRequest(criteria, QueryResultSettings.SingleRecord);
                Shift shift = request.RequestContext.Runtime.Execute <EntityDataServiceResponse <Shift> >(dataServiceRequest, request.RequestContext).PagedEntityCollection.FirstOrDefault();

                if (shift != null)
                {
                    // Load shift tender lines.
                    PagedResult <ShiftTenderLine> shiftTenderLines = this.GetShiftEntity <ShiftTenderLine>(string.Empty, ShiftTenderLinesView, request.TerminalId, request.ShiftId, request, queryByPrimaryKey: false);

                    // Load shift account lines.
                    PagedResult <ShiftAccountLine> shiftAccountLines = this.GetShiftEntity <ShiftAccountLine>(string.Empty, ShiftAccountsView, request.TerminalId, request.ShiftId, request, queryByPrimaryKey: false);

                    shift.AccountLines = shiftAccountLines.Results.ToList();
                    shift.TenderLines  = shiftTenderLines.Results.ToList();
                }

                return(new SingleEntityDataServiceResponse <Shift>(shift));
            }
Esempio n. 3
0
            private GetReceiptServiceRequest CreateXZReportReceiptServiceRequest(GetXAndZReportReceiptRequest request)
            {
                ThrowIf.Null(request, "request");

                Shift shift;

                var shiftId     = request.ShiftId;
                var receiptType = request.ReceiptType;

                // Validates if the request is XReport or ZReport type
                if ((receiptType != ReceiptType.XReport) && (receiptType != ReceiptType.ZReport))
                {
                    throw new DataValidationException(DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ReceiptTypeNotSupported, "Only receipt types for X or Z reports are expected.");
                }

                if (receiptType == ReceiptType.XReport)
                {
                    var terminalId = request.ShiftTerminalId;
                    GetShiftDataRequest getShiftDataRequest = new GetShiftDataRequest(terminalId, shiftId);
                    shift = this.Context.Execute <SingleEntityDataServiceResponse <Shift> >(getShiftDataRequest).Entity;

                    // Validates if an open or blind-closed shift of the ShiftId can be found when requesting XReport
                    if (shift == null ||
                        (shift.Status != ShiftStatus.Open && shift.Status != ShiftStatus.BlindClosed))
                    {
                        throw new DataValidationException(
                                  DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ShiftNotFound,
                                  string.Format("No open shift information can be found using the shift Id {0} on terminal {1} for X report.", shiftId, terminalId));
                    }

                    // Calculates the shift information inorder to generate the X report
                    ShiftCalculator.Calculate(this.Context, shift, shift.TerminalId, shift.ShiftId);
                }
                else
                {
                    var terminalId = this.Context.GetTerminal().TerminalId;
                    GetLastClosedShiftDataRequest getLastClosedShiftDataRequest = new GetLastClosedShiftDataRequest(terminalId);
                    shift = this.Context.Execute <SingleEntityDataServiceResponse <Shift> >(getLastClosedShiftDataRequest).Entity;

                    // Validates if a closed shift of the ShiftId can be found when requesting XReport
                    if (shift == null || shift.Status != ShiftStatus.Closed)
                    {
                        throw new DataValidationException(
                                  DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_ShiftNotFound,
                                  string.Format("No closed shift information can be found using the shift Id {0} on terminal {1} for Z report.", shiftId, terminalId));
                    }
                }

                var getReceiptServiceRequest = new GetReceiptServiceRequest(
                    shift,
                    new List <ReceiptType>()
                {
                    receiptType
                }.AsReadOnly(),
                    request.HardwareProfileId);

                return(getReceiptServiceRequest);
            }
            /// <summary>
            /// Gets the last closed shift.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <returns>A single entity data service response.</returns>
            private SingleEntityDataServiceResponse <Shift> GetLastClosedShift(GetLastClosedShiftDataRequest request)
            {
                ThrowIf.Null(request, "request");
                ThrowIf.NullOrWhiteSpace(request.TerminalId, "request.TerminalId");

                long channelId = request.RequestContext.GetPrincipal().ChannelId;

                var query = new SqlPagedQuery(QueryResultSettings.FirstRecord)
                {
                    From    = ShiftsView,
                    Where   = "CHANNEL = @ChannelId AND CLOSEDATTERMINAL = @TerminalId AND STATUS = @Status",
                    OrderBy = "CLOSEDATETIMEUTC DESC"
                };

                query.Parameters["@ChannelId"]  = channelId;
                query.Parameters["@TerminalId"] = request.TerminalId;
                query.Parameters["@Status"]     = (int)ShiftStatus.Closed;

                Shift lastShift = null;

                using (var sqlServerDatabaseContext = new SqlServerDatabaseContext(request))
                {
                    lastShift = sqlServerDatabaseContext.ReadEntity <Shift>(query).Results.FirstOrDefault();
                }

                if (lastShift != null)
                {
                    GetShiftDataRequest getShiftDataRequest = new GetShiftDataRequest(lastShift.TerminalId, lastShift.ShiftId);
                    lastShift = request.RequestContext.Execute <SingleEntityDataServiceResponse <Shift> >(getShiftDataRequest).Entity;

                    // Convert UTC time to channel time.
                    if (lastShift.StartDateTime != null)
                    {
                        lastShift.StartDateTime = new DateTimeOffset(lastShift.StartDateTime.Value.DateTime, new TimeSpan(0));
                    }

                    if (lastShift.StatusDateTime != null)
                    {
                        lastShift.StatusDateTime = new DateTimeOffset(lastShift.StatusDateTime.Value.DateTime, new TimeSpan(0));
                    }

                    if (lastShift.CloseDateTime != null)
                    {
                        lastShift.CloseDateTime = new DateTimeOffset(lastShift.CloseDateTime.Value.DateTime, new TimeSpan(0));
                    }
                }

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