/// <summary>
        /// Method to validate payout by fleet card
        /// </summary>
        /// <param name="allowSwipe">Allow Swipe</param>
        /// <param name="error">Error message</param>
        /// <returns>Caption</returns>
        public string ValidateFleetPayout(out bool allowSwipe, out ErrorMessage error)
        {
            allowSwipe = _policyManager.SWIPE_CARD;
            error      = new ErrorMessage();
            string caption;
            var    offSet = _policyManager.LoadStoreInfo().OffSet;

            if (!_policyManager.U_AllowFlPay)
            {
                MessageType temp_VbStyle = (int)MessageType.Exclamation + MessageType.OkOnly;
                error.MessageStyle = _resourceManager.CreateMessage(offSet, 12, 83, null, temp_VbStyle);
                error.StatusCode   = System.Net.HttpStatusCode.Forbidden;
                return(null);
            }
            // There are no Cards Defined on which payments can be accepted
            if (!_tenderManager.AreCardsDefined())
            {
                MessageType temp_VbStyle = (int)MessageType.Critical + MessageType.OkOnly;
                error.MessageStyle = _resourceManager.CreateMessage(offSet, 22, 91, null, temp_VbStyle);
                error.StatusCode   = System.Net.HttpStatusCode.OK;
            }
            if (allowSwipe && (!_policyManager.ScanLoyCard))
            {
                caption = _resourceManager.CreateCaption(offSet, 63, Convert.ToInt16(22), null, 3);//"Manual Entry or Swipe a Card"
            }
            else if (_policyManager.ScanLoyCard)
            {
                caption = _resourceManager.CreateCaption(offSet, 63, Convert.ToInt16(22), null, 4); // "Manual Entry or Scan a Card"
            }
            else
            {
                caption = _resourceManager.CreateCaption(offSet, 63, Convert.ToInt16(22), null, 2); // "Manual Entry Only"                                                                                                  //        optAccount.Value = True 'binal
            }
            return(caption);
        }
        /// <summary>
        /// Get Tier and Levels for all pumps
        /// </summary>
        /// <returns></returns>
        public TierLevelResponse GetAllPumps()
        {
            var offSet = _policyManager.LoadStoreInfo().OffSet;
            var result = new TierLevelResponse
            {
                PageCaption    = _resourceManager.CreateCaption(offSet, 24, 44, null, 1),
                PumpTierLevels = GetPumpsTierLevel(),
                Tiers          = GetAllTiers(),
                Levels         = GetAllLevels()
            };

            return(result);
        }
        /// <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);
        }
        /// <summary>
        /// Check Security
        /// </summary>
        /// <param name="security">Security</param>
        /// <param name="store">Store</param>
        /// <returns>True or false</returns>
        private bool CheckSecurity(ref Security security, Store store)
        {
            var dateStart = DateTime.Now;

            Performancelog.Debug($"Start,LoginManager,CheckSecurity,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");


            SetPolicyFeatures(security);
            var offSet = _policyManager.LoadStoreInfo().OffSet;

            if (security.Security_Key.Length == 0 && security.Install_Date != DateTime.FromOADate(0)) // first time
            {
                // We dont give them permission to work without security key
                if (DateAndTime.DateDiff(DateInterval.Day, security.Install_Date, DateTime.Now) < 0 && security.Install_Date <= DateAndTime.Today) // installation time
                {
                    security.Message    = $"System Is Going To Shut Down in {5 - DateAndTime.DateDiff("d", security.Install_Date, DateTime.Now)}  days";
                    security.ExpireDate = DateTime.FromOADate(security.Install_Date.ToOADate() + 5);
                    return(true);
                }
                //"License Expired. Please get a Valid Security Code from your Dealer."
                security.Message = _resourceManager.CreateCaption(offSet, 5, 83, null, 0);
                return(false); // installation time is over
            }
            if (security.Install_Date == DateTime.FromOADate(0) || security.Install_Date > DateAndTime.Today)
            {
                //"You don't have permission to login to POS. Please contact your Dealer.";
                security.Message = _resourceManager.CreateCaption(offSet, 6, 83, null, 0);
                return(false);
            }
            if (security.Security_Key.Length > 0)
            {
                //"You don't have permission to login to POS. Please contact your Dealer.";
                security.Message = _resourceManager.CreateCaption(offSet, 6, 83, null, 0);

                var secStr = Convert.ToString(store.Name);
                secStr = secStr + store.Address.Street1;
                secStr = secStr + store.Address.City;
                secStr = secStr + store.Address.PostalCode;
                secStr = secStr + store.RegNum;
                secStr = secStr + DateAndTime.Month(security.Install_Date).ToString("00") + "/" +
                         DateAndTime.Day(security.Install_Date).ToString("00") + "/" +
                         DateAndTime.Year(security.Install_Date).ToString("0000");
                secStr = secStr + security.POS_BO_Features;
                secStr = secStr + security.Pump_Features;



                var secStrNoNic = secStr;
                secStr = secStr + security.NIC_Number;
                var strTmp = security.Number_OF_POS.ToString();
                strTmp      = strTmp + Convert.ToString(security.MaxConcurrentPOS);
                strTmp      = strTmp + _utilityService.GetIpAddresses();
                secStr      = secStr + strTmp;
                secStrNoNic = secStrNoNic + strTmp;


                short i;
                for (i = 1; i <= security.Limit.Length - 1; i++)
                {
                    if (Helper.GetKey(secStr + security.Limit[i].Trim()) == security.Security_Key)
                    {
                        switch (security.Limit[i].Trim())
                        {
                        case "30":
                        case "45":
                        case "60":
                        case "75":
                        case "90":
                        case "120":
                        case "180":
                            if (DateAndTime.DateDiff(DateInterval.Day, security.Install_Date, DateTime.Now) <= Conversion.Val(security.Limit[i]))
                            {
                                // $"System Is Going To Shut Down in {Convert.ToInt64(security.Limit[i]) - DateAndTime.DateDiff("d", security.Install_Date, DateTime.Now)}  days";

                                security.Message    = _resourceManager.CreateCaption(offSet, 4, 83, Conversion.Val(security.Limit[i]) - DateAndTime.DateDiff(DateInterval.Day, security.Install_Date, DateTime.Now), 0);
                                security.ExpireDate = DateTime.FromOADate(security.Install_Date.ToOADate() + Conversion.Val(security.Limit[i]));
                                return(true);
                            }
                            //"License Expired. Please Contact your Dealer.";
                            security.Message = _resourceManager.CreateCaption(offSet, 7, 83, null, 0);
                            return(false);

                        case "PAID":
                            security.Message    = string.Empty;
                            security.ExpireDate = DateTime.FromOADate(security.Install_Date.ToOADate() + 50 * 365);     // 50 Year
                            return(true);
                        }
                    }
                }



                if (Helper.GetKey(secStrNoNic + "3") == security.Security_Key)
                {
                    if (DateAndTime.DateDiff(DateInterval.Day, security.Install_Date, DateTime.Now) <= 3)
                    {
                        var strInsDate = LoadTempInstallDate();
                        if (string.IsNullOrEmpty(strInsDate))
                        {
                            SaveTempInstallDate(security.Install_Date);
                        }
                        else if (strInsDate != security.Install_Date.ToString("MM/dd/yyyy"))
                        {
                            //"You don't have permission to login to POS. Please contact your Dealer.";
                            security.Message = _resourceManager.CreateCaption(offSet, 6, 83, null, 0);
                            return(false);
                        }


                        //$"System Is Going To Shut Down in {3 - DateAndTime.DateDiff("d", security.Install_Date, DateTime.Now)}  days";
                        security.Message    = _resourceManager.CreateCaption(offSet, 4, 83, 3 - DateAndTime.DateDiff(DateInterval.Day, security.Install_Date, DateTime.Now), 0);
                        security.ExpireDate = DateTime.FromOADate(security.Install_Date.ToOADate() + 3);
                        return(true);
                    }
                    //"License Expired. Please Contact your Dealer.";
                    security.Message = _resourceManager.CreateCaption(offSet, 7, 83, null, 0);
                    return(false);
                }
            }
            Performancelog.Debug($"End,LoginManager,CheckSecurity,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(false);
        }