Esempio n. 1
0
        /// <summary>
        /// Suspend Sale
        /// </summary>
        /// <param name="tillNumber">Till number</param>
        /// <param name="saleNumber">Sale number</param>
        /// <param name="userCode">User code</param>
        /// <param name="errorMessage">Error</param>
        /// <returns>Sale</returns>
        public Sale SuspendSale(int tillNumber, int saleNumber, string userCode, out ErrorMessage errorMessage)
        {
            var dateStart = DateTime.Now;

            Performancelog.Debug($"Start,SuspendedSaleManager,SuspendSale,{string.Empty},{dateStart:hh.mm.ss.ffffff}");
            if (!CanUserSuspendSale(userCode, out errorMessage))
            {
                return(new Sale());
            }
            var sale   = _saleManager.GetCurrentSale(saleNumber, tillNumber, 0, userCode, out errorMessage);
            var offSet = _policyManager.LoadStoreInfo().OffSet;

            if (!string.IsNullOrEmpty(errorMessage.MessageStyle.Message))
            {
                return(null);
            }

            //Added for checking delete prepay crash recovery
            if (sale.DeletePrepay)
            {
                //Please complete delete prepay first!~Comlete current transaction.
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 50, null),
                    StatusCode   = HttpStatusCode.PreconditionFailed
                };
                return(null);
            }

            if (sale.Sale_Lines.Count == 0 && !_policyManager.SUSPEND_MT)
            {
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 80, null, MessageType.OkOnly),
                    StatusCode   = HttpStatusCode.BadRequest
                };
                return(null);
            }
            //Added checking not allowing suspend sale with prepay
            if (_prepayManager.PrepayItemId(ref sale) > 0)
            {
                //MsgBox ("Cannot suspend sale with prepay, Please remove the prepay sale before suspend!~Suspend a Sale.")
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 57, null, CriticalOkMessageType),
                    StatusCode   = HttpStatusCode.BadRequest
                };
                return(null);
            }
            var sharePolicy = _policyManager.SHARE_SUSP;

            _suspendedSaleService.SuspendSale("SUSPEND", sharePolicy, sale, userCode);
            CacheManager.DeleteCurrentSaleForTill(sale.TillNumber, sale.Sale_Num);
            sale = _saleManager.InitializeSale(tillNumber, sale.Register, userCode, out errorMessage);
            //Update Sale object in Cache
            CacheManager.AddCurrentSaleForTill(sale.TillNumber, sale.Sale_Num, sale);
            Performancelog.Debug($"End,SuspendedSaleManager,SuspendSale,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(sale);
        }
Esempio n. 2
0
        /// <summary>
        /// Save Bottle return
        /// </summary>
        /// <param name="brPayment">Br payment</param>
        /// <param name="userCode">User code</param>
        /// <param name="error">Error message</param>
        /// <param name="bottleReport">Report</param>
        /// <param name="openDrawer">Open drawer or not</param>
        public Sale SaveBottleReturn(BR_Payment brPayment,
                                     out ErrorMessage error, out Report bottleReport, out bool openDrawer)
        {
            bottleReport = null;
            openDrawer   = false;
            var dateStart = DateTime.Now;

            Performancelog.Debug($"Start,BottleManager,SaveBottleReturn,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");
            error = new ErrorMessage();
            var offSet       = _policyManager.LoadStoreInfo().OffSet;
            var userCode     = UserCode;
            var user         = _loginManager.GetExistingUser(userCode);
            var existingSale = _saleService.GetSaleByTillNumber(brPayment.TillNumber);

            if (existingSale != null && existingSale.Sale_Lines.Count > 0)
            {
                error.MessageStyle = new MessageStyle
                {
                    Message     = "Please finish current sale before bottle return.~Bottle Return",
                    MessageType = ExclamationOkMessageType
                };
                error.StatusCode = HttpStatusCode.Conflict;
                return(null);
            }
            if (!_policyManager.GetPol("U_BOTTLERTN", user))
            {
                error.MessageStyle = _resourceManager.CreateMessage(offSet, 38, 57, null, ExclamationOkMessageType);
                error.StatusCode   = HttpStatusCode.Forbidden;
                return(null);
            }

            if (brPayment.Amount != 0)
            {
                if (string.IsNullOrEmpty(Convert.ToString(_policyManager.GetPol("BASECURR", null))))
                {
                    error.MessageStyle = _resourceManager.CreateMessage(offSet, 18, 61, null, CriticalOkMessageType);
                    error.StatusCode   = HttpStatusCode.NotFound;
                    return(null);
                }

                if (brPayment.Amount > (decimal)Math.Abs(_policyManager.GetPol("U_BR_LIMIT", user)))
                {
                    // Exceed the bottle return limit, Please get an authorized user!
                    error.MessageStyle = _resourceManager.CreateMessage(offSet, 18, 62, null, CriticalOkMessageType);
                    error.StatusCode   = HttpStatusCode.Forbidden;
                    return(null);
                }

                if (_policyManager.OPEN_DRAWER == "Every Sale")
                {
                    openDrawer = true;
                }
                var sale = new Sale
                {
                    Sale_Totals = { Net = Convert.ToDecimal(brPayment.Amount) }
                };
                var saleTotals = sale.Sale_Totals;
                _saleManager.SetGross(ref saleTotals, sale.Sale_Totals.Net);
                sale.Sale_Totals.Gross        = saleTotals.Gross;
                sale.Sale_Totals.TotalLabel   = saleTotals.TotalLabel;
                sale.Sale_Totals.SummaryLabel = saleTotals.SummaryLabel;
                sale.Register    = brPayment.RegisterNumber;
                sale.Sale_Change = 0;

                sale.TillNumber  = Convert.ToByte(brPayment.TillNumber);
                sale.Sale_Date   = DateTime.Now;
                sale.Sale_Tender = 0;
                sale.Sale_Change = 0;
                sale.Sale_Amount = 0;
                if (_policyManager.GetPol("Penny_Adj", null) && brPayment.Amount != 0)
                {
                    sale.Sale_Totals.Penny_Adj = Helper.Calculate_Penny_Adj(Convert.ToDecimal(brPayment.Amount));
                }
                else
                {
                    sale.Sale_Totals.Penny_Adj = 0;
                }

                brPayment.Penny_Adj = sale.Sale_Totals.Penny_Adj;
                if (existingSale == null)
                {
                    brPayment.Sale_Num = _saleManager.GetCurrentSaleNo(brPayment.TillNumber, userCode, out error);
                }
                var tendBr = new Tenders();
                var tender = tendBr.Add(Convert.ToString(_policyManager.GetPol("BASECURR", null)),
                                        "Cash", 1, true, true, false, (short)1,
                                        Convert.ToString(_policyManager.GetPol("BASECURR", null)),
                                        false, 0, 0, 0.01, true, Convert.ToDouble(-brPayment.Amount),
                                        (short)1, true, false, "", "");
                _tenderManager.Set_Amount_Entered(ref tendBr, ref sale, tender, -brPayment.Amount);

                sale.Sale_Num  = Convert.ToInt32(brPayment.Sale_Num);
                sale.Sale_Type = "BTL RTN";
                var shiftNumber = _tillService.GetTill(brPayment.TillNumber).Shift;
                bottleReport = _receiptManager.Print_BottleReturn(brPayment, user.Name, DateTime.Today,
                                                                  DateTime.Now, sale.Register, (short)brPayment.TillNumber, shiftNumber);
                bottleReport.Copies = _policyManager.BottleReturnReceiptCopies;
                _bottleReturnService.SaveBottleReturnsToDbTrans(brPayment);
                _saleManager.SaveSale(sale, userCode, ref tendBr, null);
                CacheManager.DeleteCurrentSaleForTill(sale.TillNumber, sale.Sale_Num);
                //_saleManager.Clear_Sale(sale.Sale_Num,sale.TillNumber, userCode, "", null, true, false, false, out msg);
                sale = _saleManager.InitializeSale(brPayment.TillNumber, brPayment.RegisterNumber, userCode, out error);
                //Update Sale object in Cache
                CacheManager.AddCurrentSaleForTill(sale.TillNumber, sale.Sale_Num, sale);
                Performancelog.Debug($"End,BottleManager,SaveBottleReturn,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
                return(sale);
            }
            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Void sale
        /// </summary>
        /// <param name="userCode">User code</param>
        /// <param name="saleNumber">Sale number</param>
        /// <param name="tillNumber">Till number</param>
        /// <param name="voidReason">Void reason</param>
        /// <param name="errorMessage">Error</param>
        /// <param name="fs">Report content</param>
        /// <returns>Sale</returns>
        public Sale VoidSale(string userCode, int saleNumber, int tillNumber, string voidReason,
                             out ErrorMessage errorMessage, out Report fs)
        {
            fs = null;
            var dateStart = DateTime.Now;

            Performancelog.Debug($"Start,SuspendedSaleManager,VoidSale,{string.Empty},{dateStart:hh.mm.ss.ffffff}");

            var sale = _saleManager.GetCurrentSale(saleNumber, tillNumber, 0, userCode, out errorMessage);

            if (!string.IsNullOrEmpty(errorMessage.MessageStyle.Message))
            {
                return(null);
            }
            var offSet = _policyManager.LoadStoreInfo().OffSet;

            //Added for checking delete prepay crash recovery
            if (sale.DeletePrepay)
            {
                //Please complete delete prepay first!~Comlete current transaction.
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 50, null),
                    StatusCode   = HttpStatusCode.PreconditionFailed
                };
                return(null);
            }

            if (sale.Sale_Lines.Count == 0)
            {
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 77, null, MessageType.OkOnly),
                    StatusCode   = HttpStatusCode.BadRequest
                };
                return(null);
            }


            if (CountFuelLines(sale) > 1) // if there are more then 1 line with fuel do not allow to void this sale
            {
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 82, null, MessageType.OkOnly),
                    StatusCode   = HttpStatusCode.BadRequest
                };
                return(null);
            }

            //Added, not allow to void sale with prepay line

            if (_prepayManager.PrepayItemId(ref sale) > 0)
            {
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 82, null, MessageType.OkOnly),
                    StatusCode   = HttpStatusCode.BadRequest
                };
                return(null);
            }

            //crash recovery' if there is partial/ full payment donot allow void
            if (sale.Payment)
            {
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 14, null, MessageType.OkOnly),
                    StatusCode   = HttpStatusCode.BadRequest
                };
                return(null);
            }

            //Added to control void GiveX items
            string lineNumber = string.Empty;

            if (modGlobalFunctions.HasGivexSale(sale, ref lineNumber))
            {
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 22, null, CriticalOkMessageType),
                    StatusCode   = HttpStatusCode.BadRequest
                };
                return(null);
            }
            if (!CanUserVoidSale(userCode, out errorMessage))
            {
                return(null);
            }


            //added to print receipt for Void sales
            if (_policyManager.PRINT_VOID)
            {
                sale.Sale_Type = "VOID";
                Tenders nullTenders = null;
                var     fileName    = string.Empty;
                var     rePrint     = false;
                Stream  signature;
                fs = _receiptManager.Print_Receipt(sale.TillNumber, null, ref sale, ref nullTenders,
                                                   true, ref fileName, ref rePrint, out signature, userCode);
            }

            var newSale = new Sale
            {
                Sale_Num =
                    _saleManager.Clear_Sale(sale, sale.Sale_Num, sale.TillNumber, userCode, "VOID", null, true, true,
                                            false, out errorMessage)
            };

            CacheManager.DeleteCurrentSaleForTill(sale.TillNumber, sale.Sale_Num);
            newSale.TillNumber = sale.TillNumber;
            newSale.Customer   = _customerManager.LoadCustomer(string.Empty);
            newSale.Register   = sale.Register;
            newSale.SaleHead   = new SaleHead();
            newSale.Payment    = false;
            _saleHeadManager.SetSalePolicies(ref newSale);
            _saleManager.SaveTemp(ref newSale, newSale.TillNumber);
            Register register = null;

            _mainManager.SetRegister(ref register, newSale.Register);
            if (register.Customer_Display)
            {
                newSale.CustomerDisplay = _mainManager.DisplayMsgLcd(register,
                                                                     _mainManager.FormatLcdString(register, _resourceManager.GetResString(offSet, 414) + "#:",
                                                                                                  Conversion.Str(newSale.Sale_Num).Trim()), "");
            }
            CacheManager.AddCurrentSaleForTill(newSale.TillNumber, newSale.Sale_Num, newSale);
            Performancelog.Debug($"End,SuspendedSaleManager,VoidSale,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            return(newSale);
        }