예제 #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);
        }
        /// <summary>
        /// Get Stock Price details
        /// </summary>
        /// <param name="stockCode">Stock code</param>
        /// <param name="tillNumber">Till number</param>
        /// <param name="saleNumber">Sale number</param>
        /// <param name="registerNumber">Register number</param>
        /// <param name="userCode">User code</param>
        /// <param name="error">Error message</param>
        /// <returns>Stock price</returns>
        public StockPriceCheck GetStockPriceDetails(string stockCode, int tillNumber, int saleNumber, byte registerNumber, string userCode, out ErrorMessage error)
        {
            StockPriceCheck result = new StockPriceCheck {
                SpecialPriceTypes = GetSpecialPriceTypes()
            };
            Sale_Line slPrices = new Sale_Line();
            string    txtCode  = stockCode;
            var       offSet   = _policyManager.LoadStoreInfo().OffSet;
            var       sale     = _saleManager.GetCurrentSale(saleNumber, tillNumber, registerNumber, userCode, out error);

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

            slPrices.PriceCheck = true;
            //Stock_Br.Requery '  - To have the latest numbers; form
            // SLPrices.PLU_Code = cStock;
            //updated PLU setter
            _saleLineManager.SetPluCode(ref sale, ref slPrices, stockCode, out error);

            //  - For alternate codes change to the real stock code
            stockCode = slPrices.Stock_Code;

            float tePrice = 0;

            if (!string.IsNullOrEmpty(slPrices.Stock_Code))
            {
                var pd = slPrices.PRICE_DEC;
                result.IsPriceVisible = true;
                if ((slPrices.Stock_Type == 'V' || slPrices.Stock_Type == 'O') && !slPrices.ProductIsFuel)
                {
                    result.IsAvQtyVisible    = true;
                    result.AvailableQuantity = slPrices.AvailItems.ToString(CultureInfo.InvariantCulture);
                }


                var productTaxExempt = _stockService.GetProductTaxExemptByProductCode(stockCode);
                if (productTaxExempt != null)
                {
                    result.TaxExemptPrice = GetTaxFreePrice(stockCode, (float)slPrices.Regular_Price, slPrices.ProductIsFuel, ref tePrice) ? tePrice.ToString(CultureInfo.InvariantCulture) : "";
                    //
                    //                    If Policy.TE_Type = "AITE" Then ' Shiny added the if condition we are tracking separate inventory for TE product only for AITE
                    if (_policyManager.TAX_EXEMPT && _policyManager.TAX_EXEMPT && (_policyManager.TE_Type == "AITE" || (_policyManager.TE_Type != "AITE" && _policyManager.TRACK_TEINV))) //  - Only for AITE we need to track inventory separately for TE products 'If TaxExempt Then
                    {
                        if ((slPrices.Stock_Type == 'V' || slPrices.Stock_Type == 'O') && !slPrices.ProductIsFuel)
                        {
                            result.TaxExemptAvailable = productTaxExempt.Available.ToString();
                        }
                    }
                    result.IsTaxExemptVisible = true;
                }
                else
                {
                    result.IsTaxExemptVisible = false;
                }

                result.StockCode        = stockCode;
                result.Description      = slPrices.Description;
                result.RegularPriceText = slPrices.Regular_Price.ToString("#,##0." + new string('0', pd));
                var intSpPrices = (short)slPrices.SP_Prices.Count;
                if (intSpPrices != 0)
                {
                    result.FromDate = (slPrices.SP_Prices[1].FromDate).ToString("MM/dd/yyyy");
                    if (slPrices.SP_Prices[1].ToDate != System.DateTime.FromOADate(0))
                    {
                        result.IsToDateVisible  = true;
                        result.ToDate           = (slPrices.SP_Prices[1].ToDate).ToString("MM/dd/yyyy");
                        result.IsEndDateChecked = false;
                    }
                    else
                    {
                        result.IsToDateVisible  = false;
                        result.IsEndDateChecked = true;
                    }
                    if (slPrices.Price_Units == '$')
                    {
                        result.IsPerDollarChecked = true;
                    }
                    else
                    {
                        result.IsPerPercentageChecked = true;
                    }
                }
                // Get the active vendor used to pick the prices and the price type
                result.VendorId = slPrices.Vendor;

                result.IsActiveVendorPrice = _stockService.IsActiveVendorPrice(stockCode, result.VendorId);
                var type = slPrices.Price_Units == '$' ? 1 : 2;

                SP_Price sp;
                switch (slPrices.Price_Type)
                {
                case 'R':
                    result.PriceTypeText = _resourceManager.CreateCaption(offSet, 3, 39, null, 2);     // "R - Regular Price"
                    break;

                case 'S':
                    result.SalePrice = new SalePriceType {
                        Columns = 1, SalePrices = new List <PriceGrid>()
                    };
                    result.PriceTypeText        = _resourceManager.CreateCaption(offSet, 3, 39, null, 3);// "S - Sale Price"
                    result.SalePrice.ColumnText = _resourceManager.CreateCaption(offSet, 4, 39, null, (short)type);
                    foreach (SP_Price tempLoopVarSp in slPrices.SP_Prices)
                    {
                        sp = tempLoopVarSp;
                        result.SalePrice.SalePrices.Add(new PriceGrid {
                            Column1 = sp.Price.ToString("#,##0." + new string('0', pd))
                        });
                    }
                    result.IsAddButtonVisible    = false;
                    result.IsRemoveButtonVisible = false;
                    break;

                case 'F':
                    result.FirstUnitPrice = new FirstUnitPriceType {
                        Columns = 2, FirstUnitPriceGrids = new List <PriceGrid>()
                    };
                    result.PriceTypeText              = _resourceManager.CreateCaption(offSet, 3, 39, null, 4);           // "F - First Unit Price"
                    result.FirstUnitPrice.ColumnText  = _resourceManager.GetResString(offSet, 230);                       // Quantity
                    result.FirstUnitPrice.ColumnText2 = _resourceManager.CreateCaption(offSet, 4, 39, null, (short)type); // Prices


                    foreach (SP_Price tempLoopVarSp in slPrices.SP_Prices)
                    {
                        sp = tempLoopVarSp;
                        result.FirstUnitPrice.FirstUnitPriceGrids.Add(new PriceGrid {
                            Column1 = sp.From_Quantity.ToString(CultureInfo.InvariantCulture), Column2 = sp.Price.ToString("#,##0." + new string('0', pd))
                        });
                    }
                    result.IsAddButtonVisible    = true;
                    result.IsRemoveButtonVisible = true;
                    break;

                case 'I':
                    result.IncrementalPrice = new IncrementalPriceType {
                        Columns = 3, IncrementalPriceGrids = new List <PriceGrid>()
                    };

                    result.PriceTypeText = _resourceManager.CreateCaption(offSet, 3, 39, null, 5);                          // "I - Incremental Price"
                    result.IncrementalPrice.ColumnText  = _resourceManager.CreateCaption(offSet, 4, 39, null, 3);           //From
                    result.IncrementalPrice.ColumnText2 = _resourceManager.CreateCaption(offSet, 4, 39, null, 4);           // To
                    result.IncrementalPrice.ColumnText3 = _resourceManager.CreateCaption(offSet, 4, 39, null, (short)type); // Prices


                    foreach (SP_Price tempLoopVarSp in slPrices.SP_Prices)
                    {
                        sp = tempLoopVarSp;
                        result.IncrementalPrice.IncrementalPriceGrids.Add(new PriceGrid {
                            Column1 = sp.From_Quantity.ToString(CultureInfo.InvariantCulture), Column2 = sp.To_Quantity.ToString(CultureInfo.InvariantCulture), Column3 = sp.Price.ToString("#,##0." + new string('0', pd))
                        });
                    }
                    result.IsAddButtonVisible    = true;
                    result.IsRemoveButtonVisible = true;
                    break;

                case 'X':
                    result.XForPrice = new XForPriceType {
                        Columns = 2, XForPriceGrids = new List <PriceGrid>()
                    };
                    result.PriceTypeText         = _resourceManager.CreateCaption(offSet, 3, 39, null, 6);           // "X - 'X' for Price"
                    result.XForPrice.ColumnText  = _resourceManager.GetResString(offSet, 230);                       // Quantity
                    result.XForPrice.ColumnText2 = _resourceManager.CreateCaption(offSet, 4, 39, null, (short)type); // Prices


                    foreach (SP_Price tempLoopVarSp in slPrices.SP_Prices)
                    {
                        sp = tempLoopVarSp;
                        result.XForPrice.XForPriceGrids.Add(new PriceGrid {
                            Column1 = sp.From_Quantity.ToString(CultureInfo.InvariantCulture), Column2 = sp.Price.ToString("#,##0." + new string('0', pd))
                        });
                    }
                    result.IsAddButtonVisible    = true;
                    result.IsRemoveButtonVisible = true;
                    break;
                }

                if (slPrices.Group_Price == false && _policyManager.U_CHGPRICE)
                {
                    result.IsChangePriceEnable = true;
                }
                else
                {
                    result.IsChangePriceEnable = false;
                }


                result.RegularPriceText = string.Format(result.RegularPriceText, "#,##0." + new string('0', pd));
                Register register = new Register();
                _mainManager.SetRegister(ref register, registerNumber);
                if (register.Customer_Display)
                {
                    result.CustomerDisplay = _mainManager.DisplayMsgLcd(register,
                                                                        _mainManager.FormatLcdString(register, result.Description,
                                                                                                     result.RegularPriceText), System.Convert.ToString(intSpPrices != 0 ?
                                                                                                                                                       _mainManager.FormatLcdString(register, _resourceManager.GetResString(offSet, 362), "") : ""));
                }

                //  - If  sell inactive product policy is true , even if the product is inactive we can sell the same. It is only for inactive  for Purchase and ordering)
                var days = _stockService.IsStockByDayAvailable(slPrices.Stock_Code);
                if (days.Count != 0)
                {
                    // processing
                    var dayOfWeek =
                        Convert.ToString(DateAndTime.Weekday(DateAndTime.Today));
                    if (!days.Contains(dayOfWeek))
                    {
                        slPrices.Active_StockCode = true;
                        // to avoid inactive stock item message in the main screen, saleLine item is not added to the sale anyway
                        slPrices.Active_DayOfWeek = false;
                        //PM to fix the issue related to Hot Buttons on August 27, 2012
                        var msg = _resourceManager.CreateMessage(offSet, 0, 8890, txtCode.Trim());
                        result.Message             = msg.Message;
                        result.IsChangePriceEnable = false;
                        // no Else required, if it is found the product can be sold today, continue processing
                    }
                }
                else
                {
                    slPrices.Active_DayOfWeek = true; //PM on August 27, 2012
                }
                if (!slPrices.Active_StockCode || (!slPrices.Active_StockCode && !_policyManager.Sell_Inactive))
                {
                    error.MessageStyle = _resourceManager.CreateMessage(offSet, 0, 1141, txtCode.Trim());
                    error.StatusCode   = HttpStatusCode.NotFound;
                    return(null);
                }

                if (slPrices.Price_Type == 'R')
                {
                    result.IsSpecialPricingVisible = false;
                    result.IsAddButtonVisible      = false;
                    result.IsRemoveButtonVisible   = false;
                    return(result);
                }
                result.IsSpecialPricingVisible = true;
            }
            else // not a valid stock code
            {
                //Chaps_Main.DisplayMessage(this, (short)91, temp_VbStyle2, txtCode.Trim(), (byte)0);
                error.MessageStyle = _resourceManager.CreateMessage(offSet, 39, 91, txtCode.Trim());
                error.StatusCode   = HttpStatusCode.NotFound;
                return(null);
            }
            return(result);
        }