/// <summary>
        /// Method to get promos for today
        /// </summary>
        /// <returns>List of promos</returns>
        public List <Promo> GetPromosForToday()
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,PromoService,GetPromosForToday,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");

            // August 21, 2008 took out the quantity validation to implement mix and match promotions
            var strSql  = "SELECT DISTINCT [PromoHeader].[PromoID] AS PromoID, [PromoHeader].[Day] AS Day,[PromoDetail].[Qty] AS Qty, [PromoDetail].[Link] AS Link, [PromoDetail].[Amount] AS Amount,[PromoDetail].[Stock_Code],[PromoDetail].[Dept],[PromoDetail].[Sub_Dept],[PromoDetail].[SubDetail] FROM PromoHeader LEFT JOIN PromoDetail ON [PromoHeader].[PromoID] =[PromoDetail].[PromoID]  WHERE (Day IS NULL OR Day=0 OR Day=" + Convert.ToString(DateAndTime.Weekday(DateAndTime.Today)) + ") AND [PromoHeader].[EndDate]>= \'" + DateTime.Now.ToString("yyyyMMdd") + "\' AND [PromoHeader].[StartDate]<= \'" + DateTime.Now.ToString("yyyyMMdd") + "\'";
            var rsPromo = GetRecords(strSql, DataSource.CSCMaster);
            var promos  = (from DataRow fields in rsPromo.Rows
                           select new Promo
            {
                StockCode = CommonUtility.GetStringValue(fields["Stock_Code"]),
                Dept = CommonUtility.GetStringValue(fields["Dept"]),
                SubDept = CommonUtility.GetStringValue(fields["Sub_Dept"]),
                SubDetail = CommonUtility.GetStringValue(fields["SubDetail"]),
                PromoID = CommonUtility.GetStringValue(fields["PromoID"]),
                Day = CommonUtility.GetByteValue(fields["Day"]),
                TotalQty = CommonUtility.GetShortValue(fields["Qty"]),
                MaxLink = CommonUtility.GetShortValue(fields["Link"]),
                Amount = CommonUtility.GetDoubleValue(fields["Amount"])
            }).ToList();

            _performancelog.Debug($"End,PromoService,GetPromosForToday,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(promos);
        }
示例#2
0
        /// <summary>
        /// Method to load Security information
        /// </summary>
        /// <returns>Security</returns>
        public Security LoadSecurityInfo()
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,LoginService,LoadSecurityInfo,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");

            var security = new Security();
            var rs       = GetRecords("Select Install_Date,Security_Key,POS_BO_Features,Pump_Features,NIC_Number,Num_OF_POS,MaxConcurrentPOS from Setup_C", DataSource.CSCAdmin);

            if (rs == null || rs.Rows.Count == 0)
            {
                return(security);
            }
            var fields = rs.Rows[0];

            security.Install_Date_Encrypt = CommonUtility.GetStringValue(fields["Install_Date"]);
            security.Security_Key         = CommonUtility.GetStringValue(fields["Security_Key"]);
            security.POS_BO_Features      = CommonUtility.GetStringValue(fields["POS_BO_Features"]);
            security.Pump_Features        = Convert.ToString(DBNull.Value.Equals(fields["Pump_Features"]) ? new string('0', 32) : fields["Pump_Features"]);
            security.NIC_Number           = CommonUtility.GetStringValue(fields["NIC_Number"]);
            security.Number_OF_POS        = CommonUtility.GetByteValue(DBNull.Value.Equals(fields["Num_OF_POS"]) ? 0 : fields["Num_OF_POS"]);
            security.MaxConcurrentPOS     = CommonUtility.GetByteValue(DBNull.Value.Equals(fields["MaxConcurrentPOS"]) ? 0 : fields["MaxConcurrentPOS"]);
            security.ExpireDate           = DateTime.FromOADate(security.Install_Date.ToOADate() + 5);

            _performancelog.Debug($"End,LoginService,LoadSecurityInfo,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            return(security);
        }
        /// <summary>
        /// Method to load device
        /// </summary>
        /// <returns>Device</returns>
        public Device LoadDevice()
        {
            Device device = null;
            var    query  = "select max(DeviceID) as MaxID from Device";

            var records = GetRecords(query, DataSource.CSCAdmin);

            if (records.Rows.Count > 0)
            {
                var maxId = CommonUtility.GetIntergerValue(records.Rows[0]["MAXID"]);
                if (maxId > 0)
                {
                    device = new Device {
                        DeviceName = new string[maxId + 1]
                    };
                    var rsDevice = GetRecords("select * from Device", DataSource.CSCAdmin);
                    foreach (DataRow row in rsDevice.Rows)
                    {
                        device.DeviceName[CommonUtility.GetIntergerValue(row["DeviceId"])] = CommonUtility.GetStringValue(row["DeviceName"]);
                        string deviceName = CommonUtility.GetStringValue(row["DeviceName"]);
                        switch (Strings.UCase(deviceName))
                        {
                        case "SCANNER":
                            device.ScannerID = CommonUtility.GetByteValue(row["DeviceID"]);
                            break;

                        case "RECEIPTPRINTER":
                            device.ReceiptPrinterID = CommonUtility.GetByteValue(row["DeviceID"]);
                            break;

                        case "MSR":
                            device.MSRID = CommonUtility.GetByteValue(row["DeviceID"]);
                            break;

                        case "CASHDRAWER":
                            device.CashDrawerID = CommonUtility.GetByteValue(row["DeviceID"]);
                            break;

                        case "CUSTOMERDISPLAY":
                            device.CustomerDisplayID = CommonUtility.GetByteValue(row["DeviceID"]);
                            break;

                        case "REPORTPRINTER":
                            device.ReportPrinterID = CommonUtility.GetByteValue(row["DeviceID"]);
                            break;

                        case "SCALE":
                            device.ScaleID = CommonUtility.GetByteValue(row["DeviceID"]);
                            break;
                        }
                    }
                }
            }
            return(device);
        }
示例#4
0
        /// <summary>
        /// Get PumpSpace Value
        /// </summary>
        /// <returns></returns>
        public byte GetPumpSpace()
        {
            byte result    = 1;
            var  cmdtxt    = "SELECT * FROM Setup";
            var  pumpSetup = GetRecords(cmdtxt, DataSource.CSCPump);

            if (pumpSetup.Rows.Count > 0)
            {
                result = CommonUtility.GetByteValue(pumpSetup.Rows[0]["Pump_Space"]);
            }
            return(result);
        }
示例#5
0
        /// <summary>
        /// Gets the delay in seconds needed between 2 pumps operations
        /// </summary>
        /// <returns>Delay in seconds</returns>
        public int GetClickDelayForPumps()
        {
            int result    = 0;
            var cmdtxt    = "SELECT * FROM Setup";
            var pumpSetup = GetRecords(cmdtxt, DataSource.CSCPump);

            if (pumpSetup.Rows.Count > 0)
            {
                result = CommonUtility.GetByteValue(pumpSetup.Rows[0]["ClickDelay"]);
            }
            return(result);
        }
示例#6
0
        /// <summary>
        /// Method to get list of cash buttons
        /// </summary>
        /// <returns>List of cash buttons</returns>
        public List <CashButton> GetCashButtons()
        {
            var cashButtons = new List <CashButton>();
            var dt          = GetRecords("SELECT * FROM   CashButtons Order by CashButtons.Cash_Button ", DataSource.CSCMaster);

            foreach (DataRow dr in dt.Rows)
            {
                cashButtons.Add(new CashButton
                {
                    Value = CommonUtility.GetByteValue(dr["Cash_Value"])
                });
            }
            return(cashButtons);
        }
        /// <summary>
        /// Method to get promo lines
        /// </summary>
        /// <param name="promoId">Promo id</param>
        /// <param name="none"></param>
        /// <returns>List of promo lines</returns>
        public List <Promo_Line> GetPromoLines(string promoId, string none)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,PromoService,GetPromoLines,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");

            var promoLines = new List <Promo_Line>();
            var rsDetail   = GetRecords("SELECT * FROM PromoDetail WHERE PromoID=\'" + promoId + "\' ORDER BY Link, Stock_Code, Dept, Sub_Dept, SubDetail", DataSource.CSCMaster);

            foreach (DataRow fields in rsDetail.Rows)
            {
                var promoLine = new Promo_Line
                {
                    Amount     = CommonUtility.GetFloatValue(fields["Amount"]),
                    Stock_Code = CommonUtility.GetStringValue(fields["Stock_Code"]),
                    Dept       = CommonUtility.GetStringValue(fields["Dept"]),
                    Sub_Dept   = CommonUtility.GetStringValue(fields["Sub_Dept"]),
                    Sub_Detail = CommonUtility.GetStringValue(fields["SubDetail"]),
                    Link       = CommonUtility.GetByteValue(fields["Link"]),
                    Quantity   = CommonUtility.GetFloatValue(fields["Qty"])
                };
                if (CommonUtility.GetStringValue(fields["Stock_Code"]) != none)
                {
                    promoLine.Level = 1;
                }
                else if (CommonUtility.GetStringValue(fields["Dept"]) != none &&
                         CommonUtility.GetStringValue(fields["Sub_Dept"]) == none &&
                         CommonUtility.GetStringValue(fields["SubDetail"]) == none)
                {
                    promoLine.Level = 2;
                }
                else if (CommonUtility.GetStringValue(fields["Dept"]) != none &&
                         CommonUtility.GetStringValue(fields["Sub_Dept"]) != none &&
                         CommonUtility.GetStringValue(fields["SubDetail"]) == none)
                {
                    promoLine.Level = 3;
                }
                else if (CommonUtility.GetStringValue(fields["Dept"]) != none &&
                         CommonUtility.GetStringValue(fields["Sub_Dept"]) != none &&
                         CommonUtility.GetStringValue(fields["SubDetail"]) != none)
                {
                    promoLine.Level = 4;
                }
                promoLines.Add(promoLine);
            }
            _performancelog.Debug($"End,PromoService,GetPromoLines,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(promoLines);
        }
示例#8
0
        /// <summary>
        /// Method to get orginal saleLines
        /// </summary>
        /// <param name="invoiceId">Sale number</param>
        /// <param name="tillNumber">Till number</param>
        /// <param name="dataSource">Data source</param>
        /// <returns>List of sale lines</returns>
        public List <Sale_Line> GetOrginalSaleLines(int invoiceId, int tillNumber, DataSource dataSource)
        {
            var saleLines = new List <Sale_Line>();

            var rsDetail = GetRecords(" SELECT * FROM SaleLine " + " WHERE SaleLine.Sale_No = " + Convert.ToString(invoiceId) + " " + " and TILL_NUM=" + tillNumber + " ORDER BY SaleLine.Line_Num ", dataSource);

            foreach (DataRow row in rsDetail.Rows)
            {
                saleLines.Add(new Sale_Line
                {
                    Dept               = CommonUtility.GetStringValue(row["Dept"]),
                    Sub_Dept           = CommonUtility.GetStringValue(row["Sub_Dept"]),
                    Sub_Detail         = CommonUtility.GetStringValue(row["Sub_Detail"]),
                    Stock_Code         = CommonUtility.GetStringValue(row["Stock_Code"]),
                    PLU_Code           = CommonUtility.GetStringValue(row["PLU_Code"]),
                    Line_Num           = CommonUtility.GetShortValue(row["Line_Num"]),
                    Price_Type         = CommonUtility.GetCharValue(row["Price_Type"]),
                    Quantity           = CommonUtility.GetFloatValue(row["Quantity"]),
                    Amount             = CommonUtility.GetDecimalValue(row["Amount"]),
                    Discount_Adjust    = CommonUtility.GetDoubleValue(row["Disc_adj"]),
                    Line_Discount      = CommonUtility.GetDoubleValue(row["Discount"]),
                    Discount_Type      = CommonUtility.GetStringValue(row["Disc_Type"]),
                    Discount_Code      = CommonUtility.GetStringValue(row["Disc_Code"]),
                    Discount_Rate      = CommonUtility.GetFloatValue(row["Disc_Rate"]),
                    DiscountName       = CommonUtility.GetStringValue(row["DiscountName"]),
                    Associate_Amount   = CommonUtility.GetDecimalValue(row["Assoc_Amt"]),
                    User               = CommonUtility.GetStringValue(row["User"]),
                    Description        = CommonUtility.GetStringValue(row["Descript"]),
                    Loyalty_Save       = CommonUtility.GetFloatValue(row["Loyl_Save"]),
                    Units              = CommonUtility.GetStringValue(row["Units"]),
                    Serial_No          = CommonUtility.GetStringValue(row["Serial_No"]),
                    Prepay             = Convert.ToBoolean(row["Prepay"]),
                    pumpID             = CommonUtility.GetByteValue(row["pumpID"]),
                    GradeID            = CommonUtility.GetByteValue(row["GradeID"]),
                    PositionID         = CommonUtility.GetByteValue(row["PositionID"]),
                    IsTaxExemptItem    = CommonUtility.GetBooleanValue(row["TaxExempt"]),
                    Total_Amount       = CommonUtility.GetDecimalValue(row["Total_Amt"]),
                    Regular_Price      = CommonUtility.GetDoubleValue(row["Reg_Price"]),
                    price              = CommonUtility.GetDoubleValue(row["price"]),
                    FuelRebateEligible = CommonUtility.GetBooleanValue(row["FuelRebateUsed"]),
                    FuelRebate         = CommonUtility.GetDecimalValue(row["RebateDiscount"]),
                    PromoID            = CommonUtility.GetStringValue(row["PromoID"])
                });
            }
            return(saleLines);
        }
        /// <summary>
        /// Get the Shift by Shift Number
        /// </summary>
        /// <param name="shiftNumber"></param>
        /// <param name="active"></param>
        /// <returns>Shift</returns>
        public ShiftStore GetShift(int shiftNumber, int active)
        {
            var sShift = GetRecords("SELECT * from ShiftStore A where A.ShiftNumber > " + shiftNumber + " and A.Active =" + active, DataSource.CSCMaster);

            if (sShift == null || sShift.Rows.Count == 0)
            {
                return(null);
            }
            var fields = sShift.Rows[0];
            var shift  = new ShiftStore
            {
                ShiftNumber = CommonUtility.GetIntergerValue(fields["ShiftNumber"]),
                CurrentDay  = CommonUtility.GetByteValue(fields["CurrentDay"]),
                Active      = CommonUtility.GetByteValue(fields["Active"]),
                StartTime   = CommonUtility.GetDateTimeValue(fields["StartTime"])
            };

            return(shift);
        }
示例#10
0
        /// <summary>
        /// Get the next Shift
        /// </summary>
        /// <param name="shiftNumber"></param>
        /// <param name="active"></param>
        /// <param name="tillNumber"></param>
        /// <returns>Shifts</returns>
        public List <ShiftStore> GetNextShift(int shiftNumber, int active, int tillNumber)
        {
            var innerQuery = "Select ShiftNumber from Tills where Active = " + active + " and Till_Num = " + tillNumber;
            var sqlQuery   = "SELECT * from ShiftStore A where A.ShiftNumber > " + shiftNumber + " and A.Active =" + active + " and ShiftNumber Not in ( " + innerQuery + ") ORDER BY A.ShiftNumber";
            var sShifts    = GetRecords(sqlQuery, DataSource.CSCMaster);
            var shifts     = new List <ShiftStore>();

            foreach (DataRow fields in sShifts.Rows)
            {
                var shift = new ShiftStore
                {
                    ShiftNumber = CommonUtility.GetIntergerValue(fields["ShiftNumber"]),
                    CurrentDay  = CommonUtility.GetByteValue(fields["CurrentDay"]),
                    Active      = CommonUtility.GetByteValue(fields["Active"]),
                    StartTime   = CommonUtility.GetDateTimeValue(fields["StartTime"])
                };
                shifts.Add(shift);
            }
            return(shifts);
        }
示例#11
0
        /// <summary>
        /// Get Shifts
        /// </summary>
        /// <param name="active"></param>
        /// <returns>Shifts</returns>
        public List <ShiftStore> GetShifts(byte?active)
        {
            var sShifts = active.HasValue ?
                          GetRecords("select * from shiftstore where active =" + active, DataSource.CSCMaster)
                : GetRecords("select * from shiftstore order by ShiftNumber", DataSource.CSCMaster);
            var shifts = new List <ShiftStore>();

            foreach (DataRow fields in sShifts.Rows)
            {
                var shift = new ShiftStore
                {
                    ShiftNumber = CommonUtility.GetIntergerValue(fields["ShiftNumber"]),
                    CurrentDay  = CommonUtility.GetByteValue(fields["CurrentDay"]),
                    Active      = CommonUtility.GetByteValue(fields["Active"]),
                    StartTime   = CommonUtility.GetDateTimeValue(fields["StartTime"])
                };
                shifts.Add(shift);
            }
            return(shifts);
        }
示例#12
0
        /// <summary>
        /// Get User Group  by user Code
        /// </summary>
        /// <param name="userCode">User code</param>
        /// <returns>User_Group</returns>
        public User_Group GetUserGroup(string userCode)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,UserService,GetUserGroup,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");

            var userGroup = new User_Group();
            var query     =
                $"select Uig.UGroup, UGroup.UG_Name, UGroup.SecurityLevel From Uig INNER JOIN UGroup ON Uig.UGroup = UGroup.UGroup Where  Uig.[User] = '{userCode}'";
            var dt = GetRecords(query, DataSource.CSCAdmin);

            if (dt != null && dt.Rows.Count > 0)
            {
                userGroup.Code          = CommonUtility.GetStringValue(dt.Rows[0]["UGroup"]);
                userGroup.Name          = CommonUtility.GetStringValue(dt.Rows[0]["UG_Name"]);
                userGroup.SecurityLevel = CommonUtility.GetByteValue(dt.Rows[0]["SecurityLevel"]);
            }
            _performancelog.Debug($"End,TillService,GetUserGroup,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(userGroup);
        }
示例#13
0
        /// <summary>
        /// method to get the prompts associated with the cards
        /// </summary>
        /// <param name="prompts"></param>
        /// <param name="promptString"></param>
        /// <param name="profileId"></param>
        public void GetCardProfilePrompts(ref CardPrompts prompts, string promptString, string profileId)
        {
            var query = "SELECT MaxLength, MinLength, PromptMessage, PromptSeq, A.PromptID  FROM CardProfilePrompts AS A INNER JOIN CardFuelPrompts AS B ON A.PromptID = B.PromptID AND A.Type=B.Type  WHERE A.Type =\'O\' AND ProfileID = \'" + profileId + "\' " + "AND A.PromptID in ( Select PromptID from CardProfilePrompts " + " where PromptID in (select[PromptID] from " + " CardProfilePromptLink where CardPromptID =\'" + promptString + "\' " + " and ProfileID = \'" + profileId + "\') " + " and ProfileID = \'" + profileId + "\')" + "ORDER BY PromptSeq ";

            var dt = GetRecords(query, DataSource.CSCMaster);

            var cardPrompts = new List <CardPrompt>();

            foreach (DataRow dr in dt.Rows)
            {
                cardPrompts.Add(new CardPrompt
                {
                    MaxLength = CommonUtility.GetShortValue(dr["MaxLength"]),
                    MinLength = CommonUtility.GetShortValue(dr["MinLength"]),

                    PromptMessage = CommonUtility.GetStringValue(dr["PromptMessage"]),
                    PromptSeq     = CommonUtility.GetByteValue(dr["PromptSeq"]),
                    PromptID      = CommonUtility.GetShortValue(dr["PromptID"])
                });
            }
            prompts = cardPrompts;
        }
示例#14
0
        /// <summary>
        /// Gets the List of Sale Lines
        /// </summary>
        /// <param name="saleNumber">Sale number</param>
        /// <param name="tillNumber">Till number</param>
        /// <param name="saleDate">Sale date</param>
        /// <param name="discountType">Discount type</param>
        /// <param name="teType">Tax exempt type</param>
        /// <param name="taxExempt">Tax exempt name</param>
        /// <returns>List of sale lines</returns>
        public List <Sale_Line> GetSaleLineBySaleNumber(int saleNumber, int tillNumber, DateTime saleDate, string discountType, string teType, bool taxExempt)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,ReturnSaleService,GetSaleLineBySaleNumber,{string.Empty},{dateStart:hh.mm.ss.ffffff}");

            List <Sale_Line> saleLines = new List <Sale_Line>();
            DataSource       db        = DataSource.CSCTrans;

            var strSqlHead = " SELECT * FROM   SaleHead Where  SaleHead.Sale_No = " + CommonUtility.GetStringValue(saleNumber) + " AND SaleHead.TILL = " + CommonUtility.GetStringValue(tillNumber) + " AND SaleHead.T_Type IN ( \'SALE\' ,\'REFUND\', \'RUNAWAY\',\'PUMPTEST\' ) and SaleHead.SALE_AMT <> 0 ";
            var strSqlLine = " SELECT * FROM   SaleLine Where SaleLine.Sale_No = " + CommonUtility.GetStringValue(saleNumber) + " AND SaleLine.TILL_NUM = " + CommonUtility.GetStringValue(tillNumber) + "ORDER BY SaleLine.Line_Num ";

            var rsHead = GetRecords(strSqlHead, DataSource.CSCTrans);
            var rsLine = GetRecords(strSqlLine, DataSource.CSCTrans);

            // If SaleNo is not found in Trans.mdb database, then
            // look for this SaleNo in all active Tills
            if (rsHead == null || rsHead.Rows.Count == 0)
            {
                rsHead = GetRecords(strSqlHead, DataSource.CSCTills);
                rsLine = GetRecords(strSqlLine, DataSource.CSCTills);
                // If sale number is found exit for do and use this recordset
                if (rsHead != null && rsHead.Rows.Count != 0)
                {
                    db = DataSource.CSCTills;
                }
            }
            else
            {
                db = DataSource.CSCTrans;
            }
            foreach (DataRow rsLineFields in rsLine.Rows)
            {
                var saleLine = new Sale_Line
                {
                    No_Loading    = true,
                    Stock_Code    = CommonUtility.GetStringValue(rsLineFields["Stock_Code"]),
                    PLU_Code      = CommonUtility.GetStringValue(rsLineFields["PLU_Code"]),
                    Line_Num      = CommonUtility.GetShortValue(rsLineFields["Line_Num"]),
                    Price_Type    = CommonUtility.GetCharValue(rsLineFields["Price_Type"]),
                    Dept          = CommonUtility.GetStringValue(rsLineFields["Dept"]),
                    Sub_Detail    = CommonUtility.GetStringValue(rsLineFields["Sub_Detail"]),
                    Sub_Dept      = CommonUtility.GetStringValue(rsLineFields["Sub_Dept"]),
                    Quantity      = CommonUtility.GetFloatValue(rsLineFields["Quantity"]) * -1,
                    price         = CommonUtility.GetDoubleValue(rsLineFields["price"]),
                    Regular_Price = CommonUtility.GetDoubleValue(rsLineFields["Reg_Price"]),
                    Cost          = CommonUtility.GetDoubleValue(rsLineFields["Cost"]),
                    Amount        = CommonUtility.GetDecimalValue(rsLineFields["Amount"]) * -1,
                    Total_Amount  = CommonUtility.GetDecimalValue(rsLineFields["Total_Amt"]) * -1
                };

                if (!(teType == "QITE" && discountType == "D"))
                {
                    saleLine.Line_Discount = CommonUtility.GetDoubleValue(rsLineFields["Discount"]) * -1;
                }
                saleLine.Discount_Type = CommonUtility.GetStringValue(rsLineFields["Disc_Type"]);
                saleLine.Discount_Code = CommonUtility.GetStringValue(rsLineFields["Disc_Code"]);
                if (!(teType == "QITE" && discountType == "D"))
                {
                    SetDiscountRate(ref saleLine, CommonUtility.GetFloatValue(rsLineFields["Disc_Rate"]));
                }
                saleLine.Associate_Amount = CommonUtility.GetDecimalValue(rsLineFields["Assoc_Amt"]);
                saleLine.Description      = CommonUtility.GetStringValue(rsLineFields["Descript"]);
                saleLine.Loyalty_Save     = CommonUtility.GetFloatValue(rsLineFields["Loyl_Save"]);
                saleLine.Units            = CommonUtility.GetStringValue(rsLineFields["Units"]);
                saleLine.Serial_No        = CommonUtility.GetStringValue(rsLineFields["Serial_No"]);

                saleLine.Stock_Code = CommonUtility.GetStringValue(rsLineFields["Stock_Code"]);
                saleLine.pumpID     = CommonUtility.GetByteValue(rsLineFields["pumpID"]);
                saleLine.PositionID = CommonUtility.GetByteValue(rsLineFields["PositionID"]);

                saleLine.GradeID = CommonUtility.GetByteValue(rsLineFields["GradeID"]);

                saleLine.Prepay = CommonUtility.GetBooleanValue(rsLineFields["Prepay"]);

                saleLine.ManualFuel = CommonUtility.GetBooleanValue(rsLineFields["ManualFuel"]);

                saleLine.IsTaxExemptItem = CommonUtility.GetBooleanValue(rsLineFields["TaxExempt"]);

                saleLine.Gift_Num = CommonUtility.GetStringValue(rsLineFields["GC_Num"]);

                saleLine.FuelRebateEligible = CommonUtility.GetBooleanValue(rsLineFields["FuelRebateUsed"]);

                saleLine.FuelRebate = CommonUtility.GetDecimalValue(rsLineFields["RebateDiscount"]);

                saleLine.EligibleTaxEx = CommonUtility.GetBooleanValue(rsLineFields["ElgTaxExemption"]);

                saleLine.CarwashCode = CommonUtility.GetStringValue(rsLineFields["CarwashCode"]);

                if (saleLine.CarwashCode != "")
                {
                    saleLine.IsCarwashProduct = true;
                }

                if (saleLine.IsTaxExemptItem)
                {
                    if (teType == "SITE")
                    {
                        var rsPurchaseItem = GetRecords(
                            "select * from PurchaseItem Where Sale_No=" + CommonUtility.GetStringValue(saleNumber) +
                            " AND Line_No=" + CommonUtility.GetStringValue(saleLine.Line_Num), db);
                        if (rsPurchaseItem != null && rsPurchaseItem.Rows.Count != 0)
                        {
                            var rsPurchaseItemFields = rsPurchaseItem.Rows[0];

                            saleLine.OriginalPrice =
                                CommonUtility.GetFloatValue(rsPurchaseItemFields["OriginalPrice"]);
                            saleLine.TaxInclPrice = CommonUtility.GetFloatValue(rsPurchaseItemFields["Amount"]);
                        }
                        else
                        {
                            saleLine.OriginalPrice = (float)saleLine.price;
                            saleLine.TaxInclPrice  = (float)(-1 * saleLine.Amount);
                        }
                    }
                    else
                    {
                        var rsTeSaleLine = GetRecords(
                            "select * from TaxExemptSaleLine Where SALE_NO=" +
                            CommonUtility.GetStringValue(saleNumber) + " AND LINE_NUM=" +
                            CommonUtility.GetStringValue(saleLine.Line_Num), db);

                        if (rsTeSaleLine != null && rsTeSaleLine.Rows.Count != 0)
                        {
                            var rsTeSaleLineFields = rsTeSaleLine.Rows[0];

                            saleLine.OriginalPrice =
                                CommonUtility.GetFloatValue(rsTeSaleLineFields["OriginalPrice"]);

                            saleLine.TaxInclPrice =
                                CommonUtility.GetFloatValue(-1 *
                                                            CommonUtility.GetIntergerValue(
                                                                rsTeSaleLineFields["TaxIncludedAmount"]));
                        }
                        else
                        {
                            saleLine.OriginalPrice = (float)saleLine.price;
                            saleLine.TaxInclPrice  = (float)(-1 * saleLine.Amount);
                        }

                        saleLine.IsTaxExemptItem = false;
                    }
                }


                string strPromo = CommonUtility.GetStringValue(rsLineFields["PromoID"]);
                if (strPromo.Length != 0)
                {
                    saleLine.PromoID = strPromo;
                }


                saleLine.Line_Taxes = null;
                var rsLineTax =
                    GetRecords(
                        "Select * From   S_LineTax  WHERE  S_LineTax.Sale_No = " +
                        CommonUtility.GetStringValue(saleNumber) + " AND  S_LineTax.Line_No = " +
                        CommonUtility.GetStringValue(rsLineFields["Line_Num"]) + " " +
                        "Order By S_LineTax.Tax_Name ", db);
                if (rsLineTax == null || rsLineTax.Rows.Count == 0)
                {
                    if (taxExempt && (teType == "AITE" || teType == "QITE"))
                    {
                        rsLineTax =
                            GetRecords(
                                "Select * From   TaxCreditLine  WHERE  TaxCreditLine.Sale_No = " +
                                CommonUtility.GetStringValue(saleNumber) + " AND  TaxCreditLine.Line_No = " +
                                CommonUtility.GetStringValue(rsLineFields["Line_Num"]) + " " +
                                "Order By TaxCreditLine.Tax_Name ", db);
                        if (!saleLine.IsTaxExemptItem && rsLineTax.Rows.Count != 0)
                        {
                        }
                    }
                }

                foreach (DataRow rsLineTaxFields in rsLineTax.Rows)
                {
                    saleLine.Line_Taxes.Add(CommonUtility.GetStringValue(rsLineTaxFields["Tax_Name"]),
                                            CommonUtility.GetStringValue(rsLineTaxFields["Tax_Code"]),
                                            CommonUtility.GetFloatValue(rsLineTaxFields["Tax_Rate"]),
                                            CommonUtility.GetBooleanValue(rsLineTaxFields["Tax_Included"]),
                                            CommonUtility.GetFloatValue(rsLineTaxFields["Tax_Rebate_Rate"]),
                                            CommonUtility.GetDecimalValue(rsLineTaxFields["Tax_Rebate"]), "");
                }

                // Similarly, pick up the charges associated with the line.
                saleLine.Charges = null;
                var rsLineChg =
                    GetRecords(
                        "Select *  FROM   SaleChg  WHERE  SaleChg.Sale_No = " +
                        CommonUtility.GetStringValue(saleNumber) + " AND SaleChg.Line_No = " +
                        CommonUtility.GetStringValue(rsLineFields["Line_Num"]) + " Order By SaleChg.As_Code ",
                        db);
                foreach (DataRow linChrField in rsLineChg.Rows)
                {
                    var rsLcTax =
                        GetRecords(
                            "Select *  FROM   ChargeTax  WHERE  ChargeTax.Sale_No = " +
                            CommonUtility.GetStringValue(saleNumber) + " AND ChargeTax.Line_No = " +
                            CommonUtility.GetStringValue(rsLineFields["Line_Num"]) + " AND ChargeTax.As_Code = \'" +
                            CommonUtility.GetStringValue(linChrField["As_Code"]) + "\' ", db);
                    // Find any taxes that applied to those charges.
                    var lct = new Charge_Taxes();
                    foreach (DataRow rsLcTaxFields in rsLcTax.Rows)
                    {
                        lct.Add(CommonUtility.GetStringValue(rsLcTaxFields["Tax_Name"]),
                                CommonUtility.GetStringValue(rsLcTaxFields["Tax_Code"]),
                                CommonUtility.GetFloatValue(rsLcTaxFields["Tax_Rate"]),
                                CommonUtility.GetBooleanValue(rsLcTaxFields["Tax_Included"]), "");
                    }

                    saleLine.Charges.Add(CommonUtility.GetStringValue(linChrField["As_Code"]),
                                         CommonUtility.GetStringValue(linChrField["Description"]),
                                         CommonUtility.GetFloatValue(linChrField["price"]), lct, "");
                }


                saleLine.Line_Kits = GetLineKits(saleNumber,
                                                 CommonUtility.GetIntergerValue(rsLineFields["Line_Num"]), db);
                saleLines.Add(saleLine);
            }
            _performancelog.Debug($"End,ReturnSaleService,GetSaleLineBySaleNumber,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(saleLines);
        }
        /// <summary>
        /// Method to get suspended sale
        /// </summary>
        /// <param name="tillNumber">Till number</param>
        /// <param name="saleNumber">Sale number</param>
        /// <param name="shareSusp">Share suspended sale</param>
        /// <returns>Sale</returns>
        public Sale GetSuspendedSale(int tillNumber, int saleNumber, bool shareSusp)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,SuspendedSaleService,GetSuspendedSale,{string.Empty},{dateStart:hh.mm.ss.ffffff}");

            var       sale = new Sale();
            DataTable uHead;
            DataTable uLine;

            if (shareSusp)
            {
                uHead = GetRecords("select * from SusHead  WHERE SALE_NO=" + Convert.ToString(saleNumber), DataSource.CSCTills);
                uLine = GetRecords("select * from SusLine WHERE SALE_NO=" + Convert.ToString(saleNumber) + " ORDER BY SusLine.Line_Num ", DataSource.CSCTills);
            }
            else
            {
                uHead = GetRecords("select * from SusHead where TILL=" + tillNumber + " AND SALE_NO=" + Convert.ToString(saleNumber), DataSource.CSCTills);
                uLine = GetRecords("select * from SusLine where TILL_NUM=" + tillNumber + " AND SALE_NO=" + Convert.ToString(saleNumber) + " ORDER BY SusLine.Line_Num ", DataSource.CSCTills);
            }

            if (uHead.Rows.Count > 0)
            {
                sale.Sale_Num             = CommonUtility.GetIntergerValue(uHead.Rows[0]["SALE_NO"]);
                sale.TillNumber           = (byte)tillNumber;
                sale.Register             = CommonUtility.GetByteValue(uHead.Rows[0]["Regist"]);
                sale.Customer.Code        = CommonUtility.GetStringValue(uHead.Rows[0]["Client"]);
                sale.Sale_Type            = CommonUtility.GetStringValue(uHead.Rows[0]["T_type"]);
                sale.Return_Reason.Reason = CommonUtility.GetStringValue(uHead.Rows[0]["Reason"]);
                sale.Return_Reason.RType  = CommonUtility.GetStringValue(uHead.Rows[0]["Reason_Type"]);
                sale.Sale_Totals.Invoice_Discount_Type = CommonUtility.GetStringValue(uHead.Rows[0]["Disc_Type"]);
                sale.Sale_Totals.Invoice_Discount      = CommonUtility.GetDecimalValue(uHead.Rows[0]["Invc_Disc"]);
                sale.Sale_Totals.Discount_Percent      = CommonUtility.GetFloatValue(uHead.Rows[0]["Discount_Percent"]);
                sale.Void_Num = CommonUtility.GetIntergerValue(uHead.Rows[0]["Void_No"]);

                sale.Customer.LoyaltyCard    = CommonUtility.GetStringValue(uHead.Rows[0]["LoyaltyCard"]);
                sale.Customer.LoyaltyExpDate = CommonUtility.GetStringValue(uHead.Rows[0]["LoyaltyExpDate"]);
                sale.CouponID = CommonUtility.GetStringValue(uHead.Rows[0]["CouponID"]);
                sale.Upsell   = CommonUtility.GetBooleanValue(uHead.Rows[0]["Upsell"]);
                var ln = (short)0;

                foreach (DataRow row in uLine.Rows)
                {
                    ln++;
                    var sl = new Sale_Line
                    {
                        Sale_Num = CommonUtility.GetStringValue(row["sale_no"]),
                        Till_Num = sale.TillNumber
                    };
                    sale.Sale_Num       = CommonUtility.GetIntergerValue(row["sale_no"]);
                    sl.Line_Num         = ln;
                    sl.PLU_Code         = CommonUtility.GetStringValue(row["PLU_Code"]);
                    sl.Quantity         = CommonUtility.GetFloatValue(row["Quantity"]);
                    sl.price            = CommonUtility.GetDoubleValue(row["price"]);
                    sl.Amount           = CommonUtility.GetDecimalValue(row["Amount"]);
                    sl.Line_Discount    = CommonUtility.GetDoubleValue(row["Discount"]);
                    sl.Discount_Type    = CommonUtility.GetStringValue(row["Disc_Type"]);
                    sl.Discount_Adjust  = CommonUtility.GetDoubleValue(row["Disc_Adj"]);
                    sl.Discount_Code    = CommonUtility.GetStringValue(row["Disc_Code"]);
                    sl.Discount_Rate    = CommonUtility.GetFloatValue(row["Disc_Rate"]);
                    sl.DiscountName     = CommonUtility.GetStringValue(row["DiscountName"]);
                    sl.Price_Type       = CommonUtility.GetCharValue(row["Price_Type"]);
                    sl.Loyalty_Save     = CommonUtility.GetFloatValue(row["Loyl_Save"]);
                    sl.Units            = CommonUtility.GetStringValue(row["Units"]);
                    sl.Serial_No        = CommonUtility.GetStringValue(row["Serial_No"]);
                    sl.User             = CommonUtility.GetStringValue(row["User"]);
                    sl.pumpID           = CommonUtility.GetByteValue(row["pumpID"]);
                    sl.PositionID       = CommonUtility.GetByteValue(row["PositionID"]);
                    sl.GradeID          = CommonUtility.GetByteValue(row["GradeID"]);
                    sl.Gift_Certificate = CommonUtility.GetBooleanValue(row["Gift_Cert"]);
                    sl.Gift_Num         = CommonUtility.GetStringValue(row["GC_Num"]);
                    sale.TillNumber     = (byte)tillNumber;
                    sl.ManualFuel       = CommonUtility.GetBooleanValue(row["ManualFuel"]);

                    sl.IsTaxExemptItem = CommonUtility.GetBooleanValue(row["TaxExempt"]);

                    var strPromo = CommonUtility.GetStringValue(row["PromoID"]);
                    if (!string.IsNullOrEmpty(strPromo))
                    {
                        sl.PromoID = strPromo;
                    }
                    sl.Upsell       = CommonUtility.GetBooleanValue(row["Upsell"]);
                    sl.ScalableItem = CommonUtility.GetBooleanValue(row["ScalableItem"]);
                    DataTable uReason;
                    if (shareSusp)
                    {
                        uReason =
                            GetRecords(
                                "select * from SusReas  WHERE SALE_NO=" + Convert.ToString(saleNumber) +
                                " AND LINE_Num = " + ln + " ORDER BY SusReas.Line_Num", DataSource.CSCTills);
                    }
                    else
                    {
                        uReason =
                            GetRecords(
                                "select * from SusReas where TILL_NUM=" + tillNumber + " AND SALE_NO=" +
                                Convert.ToString(saleNumber) + " AND LINE_Num = " + ln +
                                " ORDER BY SusReas.Line_Num", DataSource.CSCTills);
                    }
                    var returnReason = new Return_Reason();

                    foreach (DataRow dataRow in uReason.Rows)
                    {
                        if (CommonUtility.GetStringValue(dataRow["Reason"]) != "" &
                            CommonUtility.GetStringValue(dataRow["Reason_Type"]) != "")
                        {
                            returnReason.Reason = CommonUtility.GetStringValue(dataRow["Reason"]);
                            returnReason.RType  = CommonUtility.GetStringValue(dataRow["Reason_Type"]);
                        }
                        sl.Return_Reasons.Add(returnReason.Reason, returnReason.RType, ln.ToString());
                    }
                    sale.Sale_Lines.AddLine(ln, sl, "");
                }
                _performancelog.Debug($"End,SuspendedSaleService,GetSuspendedSale,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

                return(sale);
            }
            _performancelog.Debug($"End,SuspendedSaleService,GetSuspendedSale,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(new Sale());
        }
        /// <summary>
        /// Method to set register info
        /// </summary>
        /// <param name="registerNumber">Register number</param>
        /// <param name="device">Device</param>
        /// <returns>Register</returns>
        public Register SetRegisterInfo(short registerNumber, Device device)
        {
            var rs = GetRecords("Select *  FROM Register  WHERE Register.Reg_No = " + Convert.ToString(registerNumber), DataSource.CSCAdmin);

            if (rs.Rows.Count == 0)
            {
                return(null);
            }
            var register = new Register {
                Register_Num = registerNumber
            };

            foreach (DataRow row in rs.Rows)
            {
                if (CommonUtility.GetByteValue(row["DeviceID"]) == device.ScannerID)
                {
                    register.Scanner         = CommonUtility.GetBooleanValue(row["Active"]);
                    register.Opos_Scanner    = CommonUtility.GetBooleanValue(row["UseOPOS"]);
                    register.Scanner_Name    = CommonUtility.GetStringValue(row["DeviceName"]);
                    register.Scanner_Port    = CommonUtility.GetStringValue(row["PortNum"]);
                    register.Scanner_Setting = CommonUtility.GetStringValue(row["PortSetting"]);
                }
                else if (CommonUtility.GetByteValue(row["DeviceID"]) == device.CashDrawerID)
                {
                    register.Cash_Drawer           = CommonUtility.GetBooleanValue(row["Active"]);
                    register.Opos_Cash_Drawer      = CommonUtility.GetBooleanValue(row["UseOPOS"]);
                    register.Cash_Drawer_Name      = CommonUtility.GetStringValue(row["DeviceName"]);
                    register.Cash_Drawer_Open_Code = CommonUtility.GetShortValue(row["PortNum"]);
                }
                else if (CommonUtility.GetByteValue(row["DeviceID"]) == device.CustomerDisplayID)
                {
                    register.Customer_Display      = CommonUtility.GetBooleanValue(row["Active"]);
                    register.Opos_Customer_Display = CommonUtility.GetBooleanValue(row["UseOPOS"]);
                    register.Customer_Display_Name = CommonUtility.GetStringValue(row["DeviceName"]);
                    if (CommonUtility.GetStringValue(row["DriverName"]).Length == 0)
                    {
                        register.Customer_Display_Code = 0;
                    }
                    else
                    {
                        register.Customer_Display_Code = (byte)(Conversion.Val(Strings.Left(CommonUtility.GetStringValue(row["DriverName"]), 1)));
                    }
                    register.Customer_Display_Port = CommonUtility.GetByteValue(row["PortNum"]);
                    if (CommonUtility.GetBooleanValue(row["UseOPOS"]))
                    {
                        register.Customer_Display_Len = 20;
                    }
                }
                else if (CommonUtility.GetByteValue(row["DeviceID"]) == device.ReceiptPrinterID)
                {
                    register.Receipt_Printer      = CommonUtility.GetBooleanValue(row["Active"]);
                    register.Opos_Receipt_Printer = CommonUtility.GetBooleanValue(row["UseOPOS"]);
                    register.ReceiptPrinterName   = CommonUtility.GetStringValue(row["DeviceName"]);
                    register.ReceiptDriver        = CommonUtility.GetStringValue(row["DriverName"]);
                }
                else if (CommonUtility.GetByteValue(row["DeviceID"]) == device.ReportPrinterID)
                {
                    register.Report_Printer           = CommonUtility.GetBooleanValue(row["Active"]);
                    register.Opos_Report_Printer      = CommonUtility.GetBooleanValue(row["UseOPOS"]);
                    register.Report_Printer_Name      = CommonUtility.GetStringValue(row["DeviceName"]);
                    register.Report_Printer_Driver    = CommonUtility.GetStringValue(row["DriverName"]);
                    register.Report_Printer_font      = CommonUtility.GetStringValue(row["FontName"]);
                    register.Report_Printer_font_size = CommonUtility.GetIntergerValue(row["FontSize"]);
                }
                else if (CommonUtility.GetByteValue(row["DeviceID"]) == device.MSRID)
                {
                    register.MSR      = CommonUtility.GetBooleanValue(row["Active"]);
                    register.Opos_MSR = CommonUtility.GetBooleanValue(row["UseOPOS"]);
                    register.MSR_Name = CommonUtility.GetStringValue(row["DeviceName"]);
                }
                else if (CommonUtility.GetByteValue(row["DeviceID"]) == device.ScaleID)
                {
                    register.UseScale   = CommonUtility.GetBooleanValue(row["Active"]);
                    register.OPOS_Scale = CommonUtility.GetBooleanValue(row["UseOPOS"]);
                    register.SCALE_Name = CommonUtility.GetStringValue(row["DeviceName"]);
                }
            }
            return(register);
        }
        /// <summary>
        /// Search Customers
        /// </summary>
        /// <param name="searchCriteria"></param>
        /// <param name="totalrecords"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List <Customer> Search(string searchCriteria, out int totalrecords, int pageIndex = 1, int pageSize = 100)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,CustomerService,Search,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");
            totalrecords = 0;
            var customers = new List <Customer>();
            var query     = "Select * from Client " +
                            " WHERE  (Client.CL_Status IS NULL " +
                            " OR Client.CL_Status IN (\'A\',\'F\',\'\')) " +
                            " AND (CL_NAME like \'%" + searchCriteria + "%\' OR " +
                            " CL_CODE like \'%" + searchCriteria + "%\' OR " +
                            " CL_PHONE like \'%" + searchCriteria + "%\' )" +
                            "ORDER BY CLIENT.CL_CODE, CLIENT.CL_NAME, CLIENT.CL_PHONE";
            var dt = GetPagedRecords(query, DataSource.CSCMaster, pageIndex, pageSize);

            if (dt != null)
            {
                totalrecords = dt.Rows.Count;

                customers.AddRange(from DataRow fields in dt.Rows
                                   select new Customer
                {
                    Code                  = CommonUtility.GetStringValue(fields["CL_CODE"]),
                    Name                  = CommonUtility.GetStringValue(fields["CL_NAME"]),
                    Category              = CommonUtility.GetStringValue(fields["CL_CATEG"]),
                    Address_1             = CommonUtility.GetStringValue(fields["CL_ADD1"]),
                    Address_2             = CommonUtility.GetStringValue(fields["CL_ADD2"]),
                    City                  = CommonUtility.GetStringValue(fields["CL_CITY"]),
                    Province              = CommonUtility.GetStringValue(fields["CL_PROV"]),
                    Country               = CommonUtility.GetStringValue(fields["CL_COUNTRY"]),
                    Postal_Code           = CommonUtility.GetStringValue(fields["CL_POSTAL"]),
                    Area_Code             = CommonUtility.GetStringValue(fields["CL_ACODE"]),
                    Phone                 = CommonUtility.GetStringValue(fields["CL_PHONE"]),
                    Cell_Phone            = CommonUtility.GetStringValue(fields["CL_CELL"]),
                    Fax                   = CommonUtility.GetStringValue(fields["CL_FAX"]),
                    Toll_Free             = CommonUtility.GetStringValue(fields["CL_TOLL"]),
                    E_Mail                = CommonUtility.GetStringValue(fields["CL_EMAIL"]),
                    Contact_1             = CommonUtility.GetStringValue(fields["CL_CONT1"]),
                    Contact_2             = CommonUtility.GetStringValue(fields["CL_CONT2"]),
                    Loyalty_Code          = CommonUtility.GetStringValue(fields["LO_NUM"]),
                    Loyalty_Points        = CommonUtility.GetDoubleValue(fields["LO_POINTS"]),
                    AR_Customer           = CommonUtility.GetBooleanValue(fields["CL_ARCUST"]),
                    Customer_Type         = CommonUtility.GetStringValue(fields["CL_TYPE"]),
                    Terms                 = CommonUtility.GetShortValue(fields["TERMS"]),
                    Credit_Limit          = CommonUtility.GetDoubleValue(fields["CL_LIMIT"]),
                    Current_Balance       = CommonUtility.GetDoubleValue(fields["CL_CURBAL"]),
                    CL_Status             = CommonUtility.GetStringValue(fields["CL_STATUS"]),
                    UsePO                 = CommonUtility.GetBooleanValue(fields["UsePO"]),
                    GroupID               = CommonUtility.GetStringValue(fields["GroupID"]),
                    UseFuelRebate         = CommonUtility.GetBooleanValue(fields["UseFuelRebate"]),
                    UseFuelRebateDiscount = CommonUtility.GetBooleanValue(fields["UseFuelRebateDiscount"]),
                    CL_Note               = CommonUtility.GetStringValue(fields["CL_Note"]),
                    TaxExempt             = CommonUtility.GetBooleanValue(fields["TaxExempt"]),
                    PlateNumber           = CommonUtility.GetStringValue(fields["PlateNumber"]),
                    MultiUse_PO           = CommonUtility.GetBooleanValue(fields["MultiUse_PO"]),
                    TECardNumber          = CommonUtility.GetStringValue(fields["TECardNumber"]),
                    Discount_Code         = CommonUtility.GetByteValue(fields["CUST_DISC"])
                });
            }

            _performancelog.Debug($"End,CustomerService,Search,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            return(customers);
        }
        /// <summary>
        /// Get Customer By Client Code
        /// </summary>
        /// <param name="clientCode">code</param>
        /// <returns>Customer</returns>
        public Customer GetClientByClientCode(string clientCode)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,CustomerService,GetClientByClientCode,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");
            Customer customer = null;

            var dt = GetRecords(" SELECT * FROM   Client WHERE Client.CL_Code = \'" + clientCode + "\'", DataSource.CSCMaster);

            if (dt != null && dt.Rows.Count > 0)
            {
                _performancelog.Debug($"End,CustomerService,GetClientByClientCode,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
                customer = new Customer
                {
                    Code                  = CommonUtility.GetStringValue(dt.Rows[0]["CL_CODE"]),
                    Name                  = CommonUtility.GetStringValue(dt.Rows[0]["CL_NAME"]),
                    Category              = CommonUtility.GetStringValue(dt.Rows[0]["CL_CATEG"]),
                    Address_1             = CommonUtility.GetStringValue(dt.Rows[0]["CL_ADD1"]),
                    Address_2             = CommonUtility.GetStringValue(dt.Rows[0]["CL_ADD2"]),
                    City                  = CommonUtility.GetStringValue(dt.Rows[0]["CL_CITY"]),
                    Province              = CommonUtility.GetStringValue(dt.Rows[0]["CL_PROV"]),
                    Country               = CommonUtility.GetStringValue(dt.Rows[0]["CL_COUNTRY"]),
                    Postal_Code           = CommonUtility.GetStringValue(dt.Rows[0]["CL_POSTAL"]),
                    Area_Code             = CommonUtility.GetStringValue(dt.Rows[0]["CL_ACODE"]),
                    Phone                 = CommonUtility.GetStringValue(dt.Rows[0]["CL_PHONE"]),
                    Cell_Phone            = CommonUtility.GetStringValue(dt.Rows[0]["CL_CELL"]),
                    Fax                   = CommonUtility.GetStringValue(dt.Rows[0]["CL_FAX"]),
                    Toll_Free             = CommonUtility.GetStringValue(dt.Rows[0]["CL_TOLL"]),
                    E_Mail                = CommonUtility.GetStringValue(dt.Rows[0]["CL_EMAIL"]),
                    Contact_1             = CommonUtility.GetStringValue(dt.Rows[0]["CL_CONT1"]),
                    Contact_2             = CommonUtility.GetStringValue(dt.Rows[0]["CL_CONT2"]),
                    Loyalty_Code          = CommonUtility.GetStringValue(dt.Rows[0]["LO_NUM"]),
                    Loyalty_Points        = CommonUtility.GetDoubleValue(dt.Rows[0]["LO_POINTS"]),
                    AR_Customer           = CommonUtility.GetBooleanValue(dt.Rows[0]["CL_ARCUST"]),
                    Customer_Type         = CommonUtility.GetStringValue(dt.Rows[0]["CL_TYPE"]),
                    Terms                 = CommonUtility.GetShortValue(dt.Rows[0]["TERMS"]),
                    Credit_Limit          = CommonUtility.GetDoubleValue(dt.Rows[0]["CL_LIMIT"]),
                    Current_Balance       = CommonUtility.GetDoubleValue(dt.Rows[0]["CL_CURBAL"]),
                    CL_Status             = CommonUtility.GetStringValue(dt.Rows[0]["CL_STATUS"]),
                    UsePO                 = CommonUtility.GetBooleanValue(dt.Rows[0]["UsePO"]),
                    GroupID               = CommonUtility.GetStringValue(dt.Rows[0]["GroupID"]),
                    UseFuelRebate         = CommonUtility.GetBooleanValue(dt.Rows[0]["UseFuelRebate"]),
                    UseFuelRebateDiscount = CommonUtility.GetBooleanValue(dt.Rows[0]["UseFuelRebateDiscount"]),
                    CL_Note               = CommonUtility.GetStringValue(dt.Rows[0]["CL_Note"]),
                    TaxExempt             = CommonUtility.GetBooleanValue(dt.Rows[0]["TaxExempt"]),
                    PlateNumber           = CommonUtility.GetStringValue(dt.Rows[0]["PlateNumber"]),
                    TECardNumber          = CommonUtility.GetStringValue(dt.Rows[0]["TECardNumber"]),
                    Discount_Code         = CommonUtility.GetByteValue(dt.Rows[0]["CUST_DISC"]),
                    Price_Code            = CommonUtility.GetByteValue(dt.Rows[0]["Price_Code"]),
                    MultiUse_PO           = CommonUtility.GetBooleanValue(dt.Rows[0]["UsePO"]) && CommonUtility.GetBooleanValue(dt.Rows[0]["MultiUse_PO"]),
                };

                if (!string.IsNullOrEmpty(customer.GroupID))
                {
                    var clientDt = GetRecords("select * from ClientGroup  where GroupID=\'" + customer.GroupID + "\'", DataSource.CSCMaster);
                    if (clientDt == null || clientDt.Rows.Count == 0)
                    {
                        customer.GroupID = "";
                    }
                    else
                    {
                        customer.GroupName    = CommonUtility.GetStringValue(clientDt.Rows[0]["GroupName"]);
                        customer.DiscountType = CommonUtility.GetStringValue(clientDt.Rows[0]["DiscountType"]);
                        customer.DiscountRate = CommonUtility.GetFloatValue(clientDt.Rows[0]["DiscountRate"]);
                        customer.Footer       = CommonUtility.GetStringValue(clientDt.Rows[0]["LoyaltyFooter"]);
                        customer.DiscountName = CommonUtility.GetStringValue(clientDt.Rows[0]["DiscountName"]);
                    }
                }
                // var clientCard = GetClientCardForCustomer()
            }
            _performancelog.Debug($"End,CustomerService,GetClientByClientCode,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            return(customer);
        }
示例#19
0
        /// <summary>
        /// Get SaleBy SaleNumber
        /// </summary>
        /// <param name="saleNumber">Sale number</param>
        /// <param name="tillNumber">Till number</param>
        /// <param name="saleDate">Sale date</param>
        /// <param name="defaultCustCode">Default customer code</param>
        /// <param name="isSaleFound">Sale found or not</param>
        /// <param name="isReturnable">Sale returned or not</param>
        /// <param name="teType">Taxe exempt type</param>
        /// <param name="teGetName">Tax exempt name</param>
        /// <param name="taxExemptGa">Tax exempt ga</param>
        /// <param name="pDefaultCustomer">Deafult customer</param>
        /// <returns>Sale</returns>
        public Sale GetSaleBySaleNumber(int saleNumber, int tillNumber, DateTime saleDate, string teType, bool teGetName, bool taxExemptGa, bool pDefaultCustomer, string defaultCustCode, out bool isSaleFound, out bool isReturnable)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,ReturnSaleService,GetSaleBySaleNumber,{string.Empty},{dateStart:hh.mm.ss.ffffff}");

            DataSource db        = DataSource.CSCTrans;
            bool       saleFound = false;
            Sale       sale      = new Sale();

            isSaleFound  = true;
            isReturnable = true;

            var strSqlHead = " SELECT * FROM   SaleHead Where  SaleHead.Sale_No = " + CommonUtility.GetStringValue(saleNumber) + " AND SaleHead.TILL = " + CommonUtility.GetStringValue(tillNumber) + " AND SaleHead.T_Type IN ( \'SALE\' ,\'REFUND\', \'RUNAWAY\',\'PUMPTEST\' ) and SaleHead.SALE_AMT <> 0 ";
            var rsHead     = GetRecords(strSqlHead, DataSource.CSCTrans);

            // If SaleNo is not found in Trans.mdb database, then
            // look for this SaleNo in all active Tills
            if (rsHead == null || rsHead.Rows.Count == 0)
            {
                rsHead = GetRecords(strSqlHead, DataSource.CSCTills);
                // If sale number is found exit for do and use this recordset
                if (rsHead != null && rsHead.Rows.Count != 0)
                {
                    saleFound = true;
                    db        = DataSource.CSCTills;
                }
            }
            else
            {
                saleFound = true;
                db        = DataSource.CSCTrans;
            }

            if (!saleFound)
            {
                isSaleFound  = false;
                isReturnable = false;
                return(sale);
            }
            var rsHeadFields = rsHead.Rows[0];

            if (saleDate != new DateTime() && CommonUtility.GetDateTimeValue(rsHeadFields["Sale_Date"]) < saleDate)
            {
                isReturnable = false;
                return(sale);
            }
            sale.LoadingTemp    = true;
            sale.TillNumber     = CommonUtility.GetByteValue(tillNumber);
            sale.Sale_Num       = saleNumber;
            sale.Sale_Amount    = CommonUtility.GetDecimalValue(rsHeadFields["SALE_AMT"]);
            sale.Sale_Invc_Disc = CommonUtility.GetDecimalValue(rsHeadFields["INVC_DISC"]);
            sale.TotalTaxSaved  = CommonUtility.GetFloatValue(CommonUtility.GetDecimalValue(rsHeadFields["SALE_AMT"]) - CommonUtility.GetDecimalValue(rsHeadFields["TEND_AMT"]));
            sale.Customer       = LoadCustomer(CommonUtility.GetStringValue(rsHeadFields["Client"]), pDefaultCustomer, defaultCustCode);

            if ((CommonUtility.GetStringValue(rsHeadFields["T_type"]) == "RUNAWAY" || CommonUtility.GetStringValue(rsHeadFields["T_type"]) == "PUMPTEST") && CommonUtility.GetDecimalValue(rsHeadFields["Sale_amt"]) < 0)
            {
                sale.Sale_Type = "SALE";
            }
            else
            {
                sale.Sale_Type = CommonUtility.GetStringValue(rsHeadFields["T_type"]);
            }
            sale.Void_Num     = saleNumber;
            sale.Sale_Deposit = CommonUtility.GetDecimalValue(rsHeadFields["Deposit"]);

            sale.TreatyNumber = CommonUtility.GetStringValue(rsHeadFields["TreatyNumber"]);
            if (teType != "AITE" && teType != "QITE" && teGetName)
            {
                sale.TreatyName = GetTreatyName(CommonUtility.GetStringValue(rsHeadFields["TreatyNumber"]));
            }

            sale.ReferenceNumber = CommonUtility.GetStringValue(rsHeadFields["ReferenceNum"]);
            if (sale.ReferenceNumber != "" && taxExemptGa)
            {
                sale.EligibleTaxEx = true;
            }

            //Added to load the original Loyalty Card
            var rsDiscountTender = GetRecords("select * from DiscountTender where SALE_NO=" + CommonUtility.GetStringValue(saleNumber) + " AND TILL_NUM=" + tillNumber, db);

            if (rsDiscountTender != null && rsDiscountTender.Rows.Count != 0)
            {
                var tenderFields = rsDiscountTender.Rows[0];
                sale.Customer.LoyaltyCard = CommonUtility.GetStringValue(tenderFields["CardNum"]);
                sale.CouponID             = CommonUtility.GetStringValue(tenderFields["CouponID"]);
            }

            sale.ForCorrection = false;

            sale.Sale_Totals.Invoice_Discount_Type = Convert.ToString(rsHeadFields["Disc_Type"]);
            sale.Sale_Totals.Invoice_Discount      = Convert.ToDecimal(Convert.ToInt32(rsHeadFields["Invc_Disc"]) * -1);

            sale.Sale_Totals.Penny_Adj = Convert.ToDecimal(-1 * Convert.ToInt32(DBNull.Value.Equals(rsHeadFields["PENNY_ADJ"]) ? 0 : rsHeadFields["PENNY_ADJ"])); //
            sale.ReverseRunaway        = (string)rsHeadFields["T_type"] == "RUNAWAY" && Convert.ToInt32(rsHeadFields["Sale_amt"]) > 0;                            //
            sale.ReversePumpTest       = (string)rsHeadFields["T_type"] == "PUMPTEST" && Convert.ToInt32(rsHeadFields["Sale_amt"]) > 0;                           //

            _performancelog.Debug($"End,ReturnSaleService,GetSaleBySaleNumber,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(sale);
        }