Exemplo n.º 1
0
        /// <summary>
        /// Blind closes the current shift.
        /// </summary>
        /// <param name="transaction">The current transaction instance.</param>
        public void BlindCloseShift(IPosTransaction transaction)
        {
            if (transaction == null)
            {
                NetTracer.Warning("transaction parameter is null");
                throw new ArgumentNullException("transaction");
            }

            // Are you sure you want to close the batch?
            DialogResult dialogResult = this.Application.Services.Dialog.ShowMessage(51308, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            {
                if (dialogResult == DialogResult.Yes)
                {
                    BatchData batchData = new BatchData(Application.Settings.Database.Connection, Application.Settings.Database.DataAreaID);

                    transaction.Shift.Status           = PosBatchStatus.BlindClosed;
                    transaction.Shift.StatusDateTime   = DateTime.Now;
                    transaction.Shift.OpenedAtTerminal = string.Empty;
                    transaction.Shift.CashDrawer       = string.Empty;

                    batchData.UpdateBatch(transaction.Shift);
                    ShiftUsersCache.Remove(transaction.Shift);
                    transaction.Shift.Print();

                    this.Application.Services.Dialog.ShowMessage(51342);
                }
                else
                {
                    ((PosTransaction)transaction).EntryStatus = PosTransaction.TransactionStatus.Cancelled;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Suspend the current batch.
        /// </summary>
        /// <param name="transaction">The current transaction instance.</param>
        public void SuspendShift(IPosTransaction transaction)
        {
            if (transaction == null)
            {
                NetTracer.Warning("transaction parameter is null");
                throw new ArgumentNullException("transaction");
            }

            BatchData batchData = new BatchData(Application.Settings.Database.Connection,
                                                Application.Settings.Database.DataAreaID);

            transaction.Shift.OpenedAtTerminal = string.Empty;
            transaction.Shift.CashDrawer       = string.Empty;
            transaction.Shift.Status           = PosBatchStatus.Suspended;
            transaction.Shift.StatusDateTime   = DateTime.Now;

            batchData.UpdateBatch(transaction.Shift);
            ShiftUsersCache.Remove(transaction.Shift);
            transaction.Shift.Print();

            this.Application.Services.Dialog.ShowMessage(51342);
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Closes the current shift and print it as Z-Report.
        /// </summary>
        /// <param name="transaction">The current transaction instance.</param>
        public void CloseShift(IPosTransaction transaction)
        {
            if (transaction == null)
            {
                NetTracer.Warning("transaction parameter is null");
                throw new ArgumentNullException("transaction");
            }

            Batch batch = null;

            // Are you sure you want to close the shift ?
            if (this.Application.Services.Dialog.ShowMessage(51302, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                batch = new Batch(transaction.Shift);

                // Verify if all offline transacitons has been uploaded.
                if (!batch.VerifyOfflineTransactions())
                {
                    batch = null;
                    this.Application.Services.Dialog.ShowMessage(51341);
                }
            }

            // Calculate and verify amounts.
            if (batch != null)
            {
                // Calculate batch in background
                POSFormsManager.ShowPOSMessageWithBackgroundWorker(51303, delegate { batch.Calculate(); });

                Action <decimal, int, int> verifyAmount = delegate(decimal amount, int errorMsg, int warningMsg)
                {
                    if (amount == 0)
                    {
                        // Warning or error based on configration in HQ.
                        if ((Functions.RequireAmountDeclaration &&
                             this.Application.Services.Dialog.ShowMessage(errorMsg, MessageBoxButtons.OK, MessageBoxIcon.Exclamation) == DialogResult.OK) ||
                            (this.Application.Services.Dialog.ShowMessage(warningMsg, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No))
                        {
                            batch = null;
                        }
                    }
                };

                // Verify starting amounts.
                if (batch != null)
                {
                    verifyAmount(batch.StartingAmountTotal, 51344, 51343);
                }

                // Verify tender delcartion.
                if (batch != null)
                {
                    verifyAmount(batch.DeclareTenderAmountTotal, 51346, 51345);
                }
            }

            // Close the batch and Print Z report if everything is ok.
            if (batch != null)
            {
                batch.Status           = PosBatchStatus.Closed;
                batch.CloseDateTime    = DateTime.Now;
                batch.ClosedAtTerminal = ApplicationSettings.Terminal.TerminalId;

                BatchData batchData = new BatchData(Application.Settings.Database.Connection, Application.Settings.Database.DataAreaID);
                batchData.CloseBatch(batch);
                transaction.Shift.Status = PosBatchStatus.Closed;
                ShiftUsersCache.Remove(transaction.Shift);

                // Print Z report if user has permissions.
                IUserAccessSystem userAccessSystem = Application.BusinessLogic.UserAccessSystem;

                if (userAccessSystem.UserHasAccess(ApplicationSettings.Terminal.TerminalOperator.OperatorId, PosisOperations.PrintZ))
                {
                    POSFormsManager.ShowPOSMessageWithBackgroundWorker(99, delegate { batch.Print(ReportType.ZReport); });
                }

                this.Application.Services.Dialog.ShowMessage(51342); // Operation complete
            }
            else
            {
                NetTracer.Information("Setting status of the transaction to 'cancelled'");
                ((PosTransaction)transaction).EntryStatus = PosTransaction.TransactionStatus.Cancelled;
            }
        }