示例#1
0
        /// <summary>
        /// Determines whether [contains] [the specified shift].
        /// </summary>
        /// <param name="shift">The shift.</param>
        /// <param name="operatorId">The operator id.</param>
        /// <returns>
        ///   <c>true</c> if [contains] [the specified shift]; otherwise, <c>false</c>.
        /// </returns>
        public static bool Contains(IPosBatchStaging shift, string operatorId)
        {
            bool result = false;
            ICollection <string> userList = null;

            if (shiftUsers.TryGetValue(GetShiftId(shift), out userList) &&
                userList.Contains(operatorId))
            {
                result = true;
            }

            return(result);
        }
示例#2
0
        private void SelectShift()
        {
            if (grdView.SelectedRowsCount > 0)
            {
                SelectedShift = shiftsData[grdView.GetSelectedRows()[0]];
                DialogResult  = DialogResult.OK;
            }
            else
            {
                SelectedShift = null;
                DialogResult  = DialogResult.Cancel;
            }

            Close();
        }
示例#3
0
        /// <summary>
        /// Adds the specified user to the shift.
        /// </summary>
        /// <param name="shift">The shift.</param>
        /// <param name="operatorId">The operator id.</param>
        public static void Add(IPosBatchStaging shift, string operatorId)
        {
            string shiftId = GetShiftId(shift);
            ICollection <string> userList = null;

            if (!shiftUsers.TryGetValue(shiftId, out userList))
            {
                userList            = new Collection <string>();
                shiftUsers[shiftId] = userList;
            }

            if (!userList.Contains(operatorId))
            {
                userList.Add(operatorId);
            }
        }
示例#4
0
        /// <summary>
        /// Shows the shift selection form.
        /// </summary>
        /// <param name="mode">The mode.</param>
        /// <param name="shifts">The shifts.</param>
        /// <returns></returns>
        private static IPosBatchStaging ShowShiftSelectionForm(ShiftSelectionMode mode, IList <IPosBatchStaging> shifts)
        {
            IPosBatchStaging shift = null;

            using (ResumeShiftForm dialog = new ResumeShiftForm(mode, shifts))
            {
                // Form is shown on top of Login form, so should not use POSFormsManager
                dialog.ShowDialog();

                if (dialog.DialogResult == DialogResult.OK)
                {
                    shift = dialog.SelectedShift;
                }
            }

            return(shift);
        }
示例#5
0
        /// <summary>
        /// Print a shift staging report.
        /// </summary>
        /// <param name="batchStaging"></param>
        public static void Print(this IPosBatchStaging batchStaging)
        {
            StringBuilder reportLayout   = new StringBuilder(1000);
            int           headerStringId = 0;
            int           statusStringId = 0;

            switch (batchStaging.Status)
            {
            case PosBatchStatus.Suspended:
                headerStringId = 7063;
                statusStringId = 7067;
                break;

            case PosBatchStatus.BlindClosed:
                headerStringId = 7064;
                statusStringId = 7068;
                break;

            default:
                NetTracer.Error("Unsupported batchStaging status {0}", batchStaging.Status);
                throw new NotSupportedException();
            }

            // Header
            reportLayout.AppendLine(ApplicationLocalizer.Language.Translate(headerStringId));
            reportLayout.AppendLine();

            // Current information
            reportLayout.AppendReportLine(7006, DateTime.Now.ToShortDateString());
            reportLayout.AppendReportLine(7007, DateTime.Now.ToShortTimeString());
            reportLayout.AppendReportLine(7003, ApplicationSettings.Terminal.TerminalId);
            reportLayout.AppendLine();

            // Content
            reportLayout.AppendReportLine(7065, batchStaging.TerminalId);
            reportLayout.AppendReportLine(7005, batchStaging.BatchId);
            reportLayout.AppendReportLine(7066, ApplicationLocalizer.Language.Translate(statusStringId));
            reportLayout.AppendReportLine(7008, batchStaging.StartDateTime.ToShortDateString());
            reportLayout.AppendReportLine(7009, batchStaging.StartDateTime.ToShortTimeString());
            reportLayout.AppendReportLine(7004, batchStaging.StaffId);

            EOD.InternalApplication.Services.Peripherals.Printer.PrintReceipt(reportLayout.ToString());
        }
示例#6
0
        /// <summary>
        /// Open a shift.
        /// </summary>
        /// <param name="shift">Opened shift reference. null if shift was not opened (Non-drawer mode).</param>
        /// <returns>True if user selected any drawer or non-drawer mode, false if user canceled the operation</returns>
        public bool OpenShift(ref IPosBatchStaging shift)
        {
            string operatorId = ApplicationSettings.Terminal.TerminalOperator.OperatorId;

            // If already opened shift in memory belongs to logged on user (or assigned to user), then just return back.
            if (shift != null && (operatorId.Equals(shift.StaffId, StringComparison.OrdinalIgnoreCase) || ShiftUsersCache.Contains(shift, operatorId)))
            {
                return(true); // return without any interaction.
            }

            BatchData batchData = new BatchData(Application.Settings.Database.Connection, Application.Settings.Database.DataAreaID);
            IList <IPosBatchStaging> openedShifts = batchData.GetOpenedPosBatchesForTerminal(ApplicationSettings.Terminal.TerminalId);
            int  maxSupporedOpenedShifts          = Math.Max(1, GetAvailableDrawers().Count());// Minimum 1 shift is supported even no cash drawer available
            int  currentOpenedShifts      = openedShifts != null ? openedShifts.Count : 0;
            bool canOpenMoreShifts        = (currentOpenedShifts < maxSupporedOpenedShifts);
            bool allowMultipleShiftLogons = false; // Allow access to the shifts from other users.
            bool allowMultipleLogons      = false; // Allow multiple logons (hence multiple open shifts)
            ShiftActionResult        shiftActionResult = ShiftActionResult.None;
            IList <IPosBatchStaging> suspendedShifts   = null;

            // Try finding opened batch from database.
            if (currentOpenedShifts > 0 &&
                (shift = openedShifts.FirstOrDefault(s => operatorId.Equals(s.StaffId, StringComparison.OrdinalIgnoreCase))) != null)
            {
                return(true); // Open shift found, return without any interaction.
            }

            GetPermissions(ref allowMultipleLogons, ref allowMultipleShiftLogons);

            if (canOpenMoreShifts) // Have vacant drawers on current terminal
            {
                IPosBatchStaging shiftOnAnotherTerminal = batchData.GetPosBatchesWithStatus(PosBatchStatus.Open, operatorId).FirstOrDefault();

                if ((!allowMultipleLogons) && (shiftOnAnotherTerminal != null))
                {
                    // User is not allowed for multiple logons and
                    // owns a open shift on another terminal. Ask for action (Non-Drawer or cancel)
                    shiftActionResult = ShowShiftActionForm(51305, false, false, false, shiftOnAnotherTerminal.OpenedAtTerminal);
                }
                else
                {
                    suspendedShifts = batchData.GetPosBatchesWithStatus(PosBatchStatus.Suspended, allowMultipleShiftLogons ? null : operatorId);

                    // If there are suspended shifts?
                    if ((suspendedShifts.Count > 0) && (!Application.Settings.Database.IsOffline))
                    {
                        // And user with multiple shift permission is logging in then prompt for action.
                        if (allowMultipleShiftLogons)
                        {
                            shiftActionResult = ShowShiftActionForm(51306, true, true, false);
                        }
                        else
                        {
                            // and user without multiple shift permssions is logging in
                            shiftActionResult = ShowShiftActionForm(51307, false, true, false);
                        }
                    }
                    else
                    {
                        // A shift is not currently open on this register.
                        shiftActionResult = ShowShiftActionForm(51306, true, false, false);
                    }
                }
            }
            else // No more shifts can be opened on this register
            {
                if (allowMultipleShiftLogons)
                {
                    // User allowed for multiple shifts (Use existing, Non-Drawer or cancel)
                    shiftActionResult = ShowShiftActionForm(51309, false, false, true);
                }
                else
                {
                    // Ask for action (Non-Drawer or cancel)
                    shiftActionResult = ShowShiftActionForm(51304, false, false, false);
                }
            }

            return(ProcessShiftAction(shiftActionResult, openedShifts, suspendedShifts, ref shift));
        }
示例#7
0
        /// <summary>
        /// Processes the shift action.
        /// </summary>
        /// <param name="shiftActionResult">The shift action result.</param>
        /// <param name="openedShifts">The opened shifts.</param>
        /// <param name="suspendedShifts">The suspended shifts.</param>
        /// <param name="shift">The shift.</param>
        /// <returns>
        /// True if processed, false if canceled.
        /// </returns>
        private bool ProcessShiftAction(ShiftActionResult shiftActionResult, IList <IPosBatchStaging> openedShifts, IList <IPosBatchStaging> suspendedShifts, ref IPosBatchStaging shift)
        {
            BatchData batchData  = new BatchData(Application.Settings.Database.Connection, Application.Settings.Database.DataAreaID);
            bool      result     = false;
            string    cashDrawer = null;

            switch (shiftActionResult)
            {
            case ShiftActionResult.New:

                if (TryGetCashDrawerForShift(openedShifts, ref cashDrawer))
                {
                    PosBatchStaging newPosBatch = new PosBatchStaging();

                    newPosBatch.StoreId       = ApplicationSettings.Terminal.StoreId;
                    newPosBatch.TerminalId    = newPosBatch.OpenedAtTerminal = ApplicationSettings.Terminal.TerminalId;
                    newPosBatch.CashDrawer    = cashDrawer;
                    newPosBatch.StaffId       = ApplicationSettings.Terminal.TerminalOperator.OperatorId;
                    newPosBatch.StartDateTime = newPosBatch.StatusDateTime = DateTime.Now;
                    newPosBatch.Status        = PosBatchStatus.Open;
                    if (!ApplicationSettings.Terminal.TrainingMode)     // Don't create shift in traning mode.
                    {
                        newPosBatch.BatchId = Application.Services.ApplicationService.GetAndIncrementTerminalSeed(NumberSequenceSeedType.BatchId);
                        batchData.CreateBatch(newPosBatch);
                    }
                    shift = newPosBatch;

                    result = true;
                }
                break;

            case ShiftActionResult.Resume:
                // Let user select the shift to resume.
                shift = ShowShiftSelectionForm(ShiftSelectionMode.Resume, suspendedShifts);

                if (shift != null && TryGetCashDrawerForShift(openedShifts, ref cashDrawer))
                {
                    shift.Status           = PosBatchStatus.Open;
                    shift.StatusDateTime   = DateTime.Now;
                    shift.OpenedAtTerminal = ApplicationSettings.Terminal.TerminalId;
                    shift.CashDrawer       = cashDrawer;
                    if (!ApplicationSettings.Terminal.TrainingMode)     // Don't update batch in traning mode.
                    {
                        batchData.UpdateBatch(shift);
                    }

                    result = true;
                }
                break;

            case ShiftActionResult.UseOpened:

                if (openedShifts.Count == 1)
                {
                    shift = openedShifts.First();
                }
                else
                {
                    // Let user select the opened shift to use.
                    shift = ShowShiftSelectionForm(ShiftSelectionMode.UseOpened, openedShifts);
                }

                if (shift != null)
                {
                    ShiftUsersCache.Add(shift, ApplicationSettings.Terminal.TerminalOperator.OperatorId);
                    result = true;
                }
                break;

            case ShiftActionResult.NonDrawer:
                shift  = null;
                result = true;
                break;
            }

            return(result);
        }
示例#8
0
 /// <summary>
 /// Gets the shift id.
 /// </summary>
 /// <param name="shift">The shift.</param>
 /// <returns></returns>
 private static string GetShiftId(IPosBatchStaging shift)
 {
     return(string.Format("{0}:{1}", shift.TerminalId, shift.BatchId));
 }
示例#9
0
 /// <summary>
 /// Remove the specified shift from cache.
 /// </summary>
 /// <param name="shift">The shift.</param>
 public static void Remove(IPosBatchStaging shift)
 {
     shiftUsers.Remove(GetShiftId(shift));
 }