コード例 #1
0
        /// <summary>
        /// Unsuspend Sale
        /// </summary>
        /// <param name="saleNumber">Sale number</param>
        /// <param name="tillNumber">Till number</param>
        /// <param name="userCode">User code</param>
        /// <param name="errorMessage">Error</param>
        /// <returns>Sale</returns>
        public Sale UnsuspendSale(int saleNumber, int tillNumber, string userCode, out ErrorMessage errorMessage)
        {
            var dateStart = DateTime.Now;

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

            if (!CanUserSuspendSale(userCode, out errorMessage))
            {
                return(new Sale());
            }

            string sqlQuery;
            var    shareSusp = _policyManager.SHARE_SUSP;

            if (shareSusp)
            {
                sqlQuery = "SELECT * FROM   SusHead  WHERE  SusHead.Sale_No = " + Convert.ToString(saleNumber);
            }
            else
            {
                sqlQuery = "SELECT * FROM   SusHead  WHERE  SusHead.Sale_No = " + Convert.ToString(saleNumber) + " AND SusHead.TILL=" + tillNumber;
            }

            var susHead = _suspendedSaleService.GetAllSuspendedSale(sqlQuery);
            var offSet  = _policyManager.LoadStoreInfo().OffSet;

            if (susHead == null || susHead.Count == 0)
            {
                //"Not a Suspended Sale"
                errorMessage = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 0, 8107, saleNumber),
                    StatusCode   = HttpStatusCode.NotFound
                };
                return(null);
            }

            _suspendedSaleService.UpdateCardSaleForUnSuspend(shareSusp, tillNumber, saleNumber);
            var sale = _suspendedSaleService.GetSuspendedSale(tillNumber, saleNumber, shareSusp);

            sale.Customer = _customerManager.LoadCustomer(sale.Customer.Code);
            if (string.IsNullOrEmpty(sale.CouponID))
            {
                _saleManager.ReCompute_Coupon(ref sale);
            }
            var saleLines = sale.Sale_Lines;

            if (sale.Sale_Totals.Sale_Taxes != null)
            {
                _saleHeadManager.Load_Taxes(ref sale);
            }
            sale.Sale_Lines = new Sale_Lines();
            _suspendedSaleService.RemovePreviousTransactionFromDbTemp(tillNumber);
            foreach (Sale_Line saleLine in saleLines)
            {
                var          sl           = saleLine;
                var          quantity     = saleLine.Quantity;
                var          price        = saleLine.price;
                var          amount       = saleLine.Amount;
                var          discountRate = saleLine.Discount_Rate;
                var          discountType = saleLine.Discount_Type;
                ErrorMessage error;
                _saleLineManager.SetPluCode(ref sale, ref sl, sl.PLU_Code, out error);

                if (sl.ProductIsFuel && !sl.IsPropane)
                {
                    sl.Regular_Price = Convert.ToDouble(sl.price);
                }

                if (sl.Gift_Certificate && sl.GiftType == "LocalGift")
                {
                    sl.Description = _resourceManager.GetResString(offSet, 8124) + sl.Gift_Num;
                }
                if (sale.Void_Num != 0)
                {
                    _saleManager.Add_a_Line(ref sale, sl, userCode, tillNumber, out errorMessage, adjust: false, tableAdjust: false, forRefund: true);
                }
                else
                {
                    _saleManager.Add_a_Line(ref sale, sl, userCode, tillNumber, out errorMessage, false, false);
                }

                sl.No_Loading = false;
                if (sl.ScalableItem)
                {
                    sl.Regular_Price = sl.price;
                }

                _saleLineManager.SetPrice(ref sl, price);
                _saleLineManager.SetQuantity(ref sl, quantity);
                _saleLineManager.SetAmount(ref sl, amount);
                saleLine.Discount_Type = discountType;
                _saleLineManager.SetDiscountRate(ref sl, discountRate);
                sl.No_Loading = false; // It has to be set back to false, otherwise if the user changes the qty or price in the POS screen after unsuspend, the amount will not be right

                if (shareSusp)
                {
                    // modGlobalFunctions.Load_CardSales(Chaps_Main.dbTill, (short)0, saleNumber, SL.Line_Num);
                }
            }

            _saleManager.Sale_Discount(ref sale, Convert.ToDecimal(sale.Sale_Totals.Invoice_Discount),
                                       Convert.ToString(sale.Sale_Totals.Invoice_Discount_Type), false);
            _suspendedSaleService.DeleteUnsuspend(shareSusp, tillNumber, saleNumber);
            _suspendedSaleService.DeleteCardSaleFromDbTemp(saleNumber);
            sale.Sale_Type = "CANCEL";
            //Update Sale object in Cache
            CacheManager.AddCurrentSaleForTill(tillNumber, sale.Sale_Num, sale);
            Performancelog.Debug($"End,SuspendedSaleManager,UnsuspendSale,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            Register register = new Register();

            _mainManager.SetRegister(ref register, sale.Register);
            //Added to display invoice# to customer display
            if (register.Customer_Display)
            {
                sale.CustomerDisplay = _mainManager.DisplayMsgLcd(register,
                                                                  _mainManager.FormatLcdString(register, _resourceManager.GetResString(offSet, 414) + "#:",
                                                                                               Conversion.Str(saleNumber).Trim()), "");
            }
            return(sale);
        }