Exemple #1
0
        /// <summary>
        /// Method to get prepay global
        /// </summary>
        /// <param name="pumpId">Pump id</param>
        /// <returns>Prepay</returns>
        public recPump GetPrepayGlobal(int pumpId)
        {
            var rec     = new recPump();
            var dRecset = GetRecords("SELECT * FROM PrepayGlobal  WHERE pumpID = " + Convert.ToString(pumpId), DataSource.CSCTrans);

            if (dRecset.Rows.Count == 0)
            {
                rec.IsPrepay       = false;
                rec.IsPrepayLocked = false;



                if (!(rec.IsHoldPrepay && rec.PrepayAmount > 0))
                {
                    rec.PrepayAmount    = 0;
                    rec.PrepayInvoiceID = 0;
                    rec.PrepayPosition  = 0;
                }
            }
            else
            {
                rec.PrepayAmount    = CommonUtility.GetFloatValue(dRecset.Rows[0]["Amount"]);
                rec.IsPrepayLocked  = CommonUtility.GetBooleanValue(dRecset.Rows[0]["Locked"]);
                rec.PrepayInvoiceID = CommonUtility.GetIntergerValue(dRecset.Rows[0]["InvoiceID"]);
                rec.PrepayPosition  = CommonUtility.GetShortValue(dRecset.Rows[0]["PositionID"]);
                rec.IsPrepay        = true;
            }
            return(rec);
        }
        /// <summary>
        /// Method to get tax info by stock code
        /// </summary>
        /// <param name="stockCode">Stock code</param>
        /// <returns>List of stock tax info</returns>
        public List <StockTaxInfo> GetTaxInfoByStockCode(string stockCode)
        {
            var dateStart = DateTime.Now;

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

            List <StockTaxInfo> taxes = new List <StockTaxInfo>();
            var rsTax =
                GetRecords(
                    @"SELECT A.Tax_Name, A.Tax_Code, D.Tax_Rate, D.Tax_Incl, D.Tax_Rebate  FROM StockTax as A left join (select B.TAX_NAME,B.TAX_ACTIVE, c.Tax_Rate, c.Tax_Incl, c.Tax_Rebate, c.TAX_CODE from taxMast as B join TAXRATE as c
                    on B.TAX_NAME = c.TAX_NAME) as D on A.Tax_Name = D.TAX_NAME and A.Tax_Code = D.TAX_CODE where A.Stock_Code = '" + stockCode + "' and D.Tax_Active = 1", DataSource.CSCMaster);

            foreach (DataRow dataRow in rsTax.Rows)
            {
                taxes.Add(new StockTaxInfo
                {
                    TaxName  = CommonUtility.GetStringValue(dataRow["Tax_Name"]),
                    TaxCode  = CommonUtility.GetStringValue(dataRow["Tax_Code"]),
                    Rate     = CommonUtility.GetFloatValue(dataRow["Tax_Rate"]),
                    Included = CommonUtility.GetBooleanValue(dataRow["Tax_Incl"]),
                    Rebate   = CommonUtility.GetFloatValue(dataRow["Tax_Rebate"])
                });
            }
            _performancelog.Debug($"End,TaxService,GetTaxInfoByStockCode,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(taxes);
        }
        /// <summary>
        /// Method to get test rate by tax name
        /// </summary>
        /// <param name="taxName">Tax name</param>
        /// <returns>List of tax rate</returns>
        public List <TaxRate> GetTaxRatesByName(string taxName)
        {
            var dateStart = DateTime.Now;

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

            var taxRateRecordSet = GetRecords("SELECT * FROM TaxRate  WHERE Tax_Name = \'" + taxName + "\' ", DataSource.CSCMaster);
            var taxRates         = new List <TaxRate>();

            foreach (DataRow dataRow in taxRateRecordSet.Rows)
            {
                var taxRate = new TaxRate
                {
                    TaxName        = CommonUtility.GetStringValue(dataRow["TAX_NAME"]),
                    TaxCode        = CommonUtility.GetStringValue(dataRow["TAX_CODE"]),
                    TaxDescription = CommonUtility.GetStringValue(dataRow["TAX_DESC"]),
                    Rebate         = CommonUtility.GetFloatValue(dataRow["TAX_REBATE"]),
                    Rate           = CommonUtility.GetFloatValue(dataRow["TAX_RATE"]),
                    Included       = CommonUtility.GetBooleanValue(dataRow["TAX_INCL"])
                };
                taxRates.Add(taxRate);
            }
            _performancelog.Debug($"End,TaxService,GetTaxRatesByName,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(taxRates);
        }
        /// <summary>
        /// Method to get customer group
        /// </summary>
        /// <param name="groupId">Group Id</param>
        public ClientGroup GetCustomerGroup(string groupId)
        {
            var dateStart = DateTime.Now;

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

            var clientGroup = new ClientGroup();

            if (!string.IsNullOrEmpty(groupId))
            {
                var dt = GetRecords("SELECT * FROM ClientGroup Where GroupID=\'" + groupId + "\'", DataSource.CSCMaster);
                if (dt == null || dt.Rows.Count == 0)
                {
                    _performancelog.Debug($"End,CustomerService,GetCustomerGroup,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

                    return(null);
                }
                clientGroup.GroupName    = CommonUtility.GetStringValue(dt.Rows[0]["GroupName"]);
                clientGroup.DiscountType = CommonUtility.GetStringValue(dt.Rows[0]["DiscountType"]);
                clientGroup.DiscountRate = CommonUtility.GetFloatValue(dt.Rows[0]["DiscountRate"]);
                clientGroup.Footer       = CommonUtility.GetStringValue(dt.Rows[0]["LoyaltyFooter"]);
                clientGroup.DiscountName = CommonUtility.GetStringValue(dt.Rows[0]["DiscountName"]);
            }
            _performancelog.Debug($"End,CustomerService,GetCustomerGroup,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(clientGroup);
        }
        /// <summary>
        /// Method to get purchase items
        /// </summary>
        /// <param name="saleNumber">Sale number</param>
        /// <param name="tillNumber">Till number</param>
        /// <returns>Purchase items</returns>
        public List <tePurchaseItem> GetPurchaseItems(int saleNumber, int tillNumber)
        {
            var dateStart = DateTime.Now;

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

            var purchaseItems = new List <tePurchaseItem>();
            var rsSite        = GetRecords("select * from purchaseitem inner join cscmaster.dbo.ProductTaxExempt b " + " on purchaseitem.CscPurchaseItemKey = b.UpcCode Where sale_no =" + Convert.ToString(saleNumber) + " and Till_no =" + Convert.ToString(tillNumber), DataSource.CSCTills);


            foreach (DataRow row in rsSite.Rows)
            {
                purchaseItems.Add(new tePurchaseItem
                {
                    TreatyNo    = CommonUtility.GetStringValue(row["TreatyNo"]),
                    ProductType = CommonUtility.GetStringValue(row["CategoryCodeFK"]),
                    Quantity    = CommonUtility.GetShortValue(row["Quantity"]),
                    UnitsPerPkg = CommonUtility.GetFloatValue(row["UnitsPerPkg"])
                });
            }

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

            return(purchaseItems);
        }
Exemple #6
0
        /// <summary>
        /// Method to load prepay
        /// </summary>
        /// <param name="pumpId">Pump Id</param>
        /// <returns>Prepay</returns>
        public recPump LoadPrepay(int pumpId)
        {
            recPump rec;
            var     dRecset = GetRecords("SELECT * FROM PrepayGlobal  WHERE pumpID = " + Convert.ToString(pumpId), DataSource.CSCTrans);

            if (dRecset.Rows.Count == 0)
            {
                rec = new recPump
                {
                    IsHoldPrepay    = false,
                    IsPrepay        = false,
                    PrepayAmount    = 0,
                    IsPrepayLocked  = false,
                    PrepayInvoiceID = 0,
                    PrepayPosition  = 0
                };
            }
            else
            {
                rec = new recPump
                {
                    IsHoldPrepay    = true,
                    IsPrepay        = true,
                    PrepayAmount    = CommonUtility.GetFloatValue(dRecset.Rows[0]["Amount"]),
                    IsPrepayLocked  = CommonUtility.GetBooleanValue(dRecset.Rows[0]["Locked"]),
                    PrepayInvoiceID = CommonUtility.GetIntergerValue(dRecset.Rows[0]["InvoiceID"]),
                    PrepayPosition  = CommonUtility.GetShortValue(dRecset.Rows[0]["PositionID"])
                };
            }
            return(rec);
        }
Exemple #7
0
        public List <ClientGroup> GetClientGroups()
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,FuelDiscountService,GetCustomerGroups,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");
            var dt = GetRecords("SELECT * FROM ClientGroup", DataSource.CSCMaster);

            if (dt == null || dt.Rows.Count == 0)
            {
                _performancelog.Debug($"End,CustomerService,GetCustomerGroups,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

                return(null);
            }
            List <ClientGroup> cgs = new List <ClientGroup>();
            ClientGroup        cg;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                cg              = new ClientGroup();
                cg.GroupName    = CommonUtility.GetStringValue(dt.Rows[i]["GroupName"]);
                cg.DiscountType = CommonUtility.GetStringValue(dt.Rows[i]["DiscountType"]);
                cg.DiscountRate = CommonUtility.GetFloatValue(dt.Rows[i]["DiscountRate"]);
                cg.Footer       = CommonUtility.GetStringValue(dt.Rows[i]["LoyaltyFooter"]);
                cg.DiscountName = CommonUtility.GetStringValue(dt.Rows[i]["DiscountName"]);
                cg.GroupId      = CommonUtility.GetStringValue(dt.Rows[i]["GroupID"]);
                cgs.Add(cg);
            }

            _performancelog.Debug($"End,FuelDiscountService,GetCustomerGroups,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            return(cgs);
        }
Exemple #8
0
        /// <summary>
        /// Get Maximum Dip value For Tank No
        /// </summary>
        /// <param name="tankno">Tank number</param>
        /// <returns>Maximum dip</returns>
        public float MaximumDip(byte tankno)
        {
            float returnValue;

            var dt = GetRecords("Select TankCode from TankInfo where ID = " + CommonUtility.GetStringValue(tankno), DataSource.CSCPump);

            if (dt != null && dt.Rows.Count > 0)
            {
                var rs = GetRecords("SELECT Length, Diameter, Capacity, TankEnds, Orientation,ReadingType, UseChart FROM   TankType WHERE  TankCode = \'" + CommonUtility.GetStringValue(dt.Rows[0]["TankCode"]) + "\' ", DataSource.CSCPump);
                if (rs != null && rs.Rows.Count > 0)
                {
                    if (Strings.UCase(CommonUtility.GetStringValue(rs.Rows[0]["Readingtype"])) == "G")
                    {
                        returnValue = 100;
                    }
                    else
                    {
                        if (CommonUtility.GetBooleanValue(rs.Rows[0]["UseChart"]) == false)
                        {
                            if (Strings.UCase(CommonUtility.GetStringValue(rs.Rows[0]["Orientation"])) == "H")
                            {
                                // For horizontal tanks it's the diameter
                                returnValue = CommonUtility.GetFloatValue(rs.Rows[0]["Diameter"]);
                            }
                            else
                            {
                                // For vertical tanks its the length
                                returnValue = CommonUtility.GetFloatValue(rs.Rows[0]["length"]);
                            }
                        }
                        else
                        {
                            var rsMax = GetRecords("select max(Depth) as [MaxDip] from TankChart Where   DipChart = \'" + CommonUtility.GetStringValue(dt.Rows[0]["TankCode"]) + "\' ", DataSource.CSCPump);
                            if (rsMax != null && rsMax.Rows.Count > 0)
                            {
                                returnValue = CommonUtility.GetFloatValue(rsMax.Rows[0]["maxdip"]);
                            }
                            else
                            {
                                returnValue = 0;
                            }
                        }
                    }
                }
                else
                {
                    // If the Tank Type wasn't found in the database then
                    // load dummy values.
                    returnValue = 0;
                }
            }
            else
            {
                returnValue = 0;
            }
            return(returnValue);
        }
        /// <summary>
        /// Method to load GST exempt
        /// </summary>
        /// <param name="taxExemptSale">Tax exempt sale</param>
        /// <param name="sn">Sale number</param>
        /// <param name="tillId">Till number</param>
        /// <param name="db">Data source</param>
        /// <returns>True or false</returns>
        public bool LoadGstExempt(ref TaxExemptSale taxExemptSale, int sn, byte tillId,
                                  DataSource db)
        {
            var rsLine = GetRecords("select * from SALELINE " + " where SALE_NO=" + Convert.ToString(sn) + " AND TILL_NUM=" + Convert.ToString(tillId), db);

            if (rsLine.Rows.Count == 0)
            {
                return(false);
            }

            foreach (DataRow line in rsLine.Rows)
            {
                var rsTaxCreditLine = GetRecords("SELECT * from TaxCreditLine where TILL_NUM=" + Convert.ToString(tillId) + " AND SALE_NO=" + Convert.ToString(sn) + " AND Line_No=" + Convert.ToString(line["Line_Num"]), db);
                if (rsTaxCreditLine.Rows.Count == 0)
                {
                    continue;
                }
                var tx = new TaxCreditLine {
                    Line_Num = CommonUtility.GetShortValue(line["Line_Num"])
                };
                foreach (DataRow taxCreditLine in rsTaxCreditLine.Rows)
                {
                    var lt = new Line_Tax
                    {
                        Tax_Name         = CommonUtility.GetStringValue(taxCreditLine["Tax_Name"]),
                        Tax_Code         = CommonUtility.GetStringValue(taxCreditLine["Tax_Code"]),
                        Tax_Rate         = CommonUtility.GetFloatValue(taxCreditLine["Tax_Rate"]),
                        Tax_Included     = CommonUtility.GetBooleanValue(taxCreditLine["Tax_Included"]),
                        Tax_Added_Amount = CommonUtility.GetFloatValue(taxCreditLine["Tax_Added_Amount"]),
                        Tax_Incl_Amount  = CommonUtility.GetFloatValue(taxCreditLine["Tax_Included_Amount"])
                    };
                    tx.Line_Taxes.AddTaxLine(lt, "");
                }
                taxExemptSale.TaxCreditLines.AddLine(tx.Line_Num, tx, "");
            }


            var rsTaxCredit = GetRecords("SELECT * from TaxCredit where TILL_NUM=" + Convert.ToString(tillId)
                                         + " AND SALE_NO=" + Convert.ToString(sn), db);

            foreach (DataRow taxCredit in rsTaxCredit.Rows)
            {
                var sx = new Sale_Tax
                {
                    Tax_Name            = CommonUtility.GetStringValue(taxCredit["Tax_Name"]),
                    Tax_Code            = CommonUtility.GetStringValue(taxCredit["Tax_Code"]),
                    Tax_Rate            = CommonUtility.GetFloatValue(taxCredit["Tax_Rate"]),
                    Taxable_Amount      = CommonUtility.GetDecimalValue(taxCredit["Taxable_Amount"]),
                    Tax_Added_Amount    = CommonUtility.GetDecimalValue(taxCredit["Tax_Added_Amount"]),
                    Tax_Included_Amount = CommonUtility.GetDecimalValue(taxCredit["Tax_Included_Amount"]),
                    Tax_Included_Total  = CommonUtility.GetDecimalValue(taxCredit["Tax_Included_Total"])
                };
                taxExemptSale.TaxCredit.Add(sx.Tax_Name, sx.Tax_Code, sx.Tax_Rate, sx.Taxable_Amount, sx.Tax_Added_Amount, sx.Tax_Included_Amount, sx.Tax_Included_Amount, sx.Tax_Rebate_Rate, sx.Tax_Rebate, sx.Tax_Name + sx.Tax_Code); //   - gave mismatch type error for AITE
            }
            return(true);
        }
Exemple #10
0
        /// <summary>
        /// Method to get discount rate of fuel
        /// </summary>
        /// <param name="groupId">Group id</param>
        /// <param name="gradeId">Grade id</param>
        /// <returns>DIscount rate</returns>
        public float?GetDiscountRate(string groupId, string gradeId)
        {
            var dt = GetRecords("SELECT DiscountRate FROM FuelDiscountChart  WHERE GroupID = \'" + groupId + "\' and Grade= " + Convert.ToString(gradeId), DataSource.CSCMaster);

            if (dt != null && dt.Rows.Count > 0)
            {
                return(CommonUtility.GetFloatValue(dt.Rows[0]["DiscountRate"]));
            }
            return(null);
        }
Exemple #11
0
        /// <summary>
        /// Method to get line kit
        /// </summary>
        /// <param name="db">Data source</param>
        /// <param name="sn">Sale number</param>
        /// <param name="ln">Line number</param>
        /// <returns>Line kits</returns>
        public Line_Kits Get_Line_Kit(DataSource db, int sn, int ln)
        {
            Line_Kits lk = new Line_Kits();

            // Get the kit items in the line
            var rsLineKit = GetRecords("Select *  FROM   SaleKit  WHERE  SaleKit.Sale_No = " + Convert.ToString(sn)
                                       + " AND " + "       SaleKit.Line_No = " + Convert.ToString(ln) + " ", db);

            foreach (DataRow lineKit in rsLineKit.Rows)
            {
                // Charges on Kit items
                var rsLineKitChg = GetRecords("Select *  FROM   SaleKitChg  WHERE  SaleKitChg.Sale_No = "
                                              + Convert.ToString(sn) + " AND " + "       SaleKitChg.Line_No = " + Convert.ToString(ln)
                                              + " AND " + "       SaleKitChg.Kit_Item = \'" + CommonUtility.GetStringValue(lineKit["Kit_Item"]) + "\' ", db);

                var lkc = new K_Charges();
                foreach (DataRow kitCharge in rsLineKitChg.Rows)
                {
                    // Taxes on Charges on Kit items
                    var rsCgt = GetRecords("Select *  FROM   SaleKitChgTax  WHERE  SaleKitChgTax.Sale_No  = "
                                           + Convert.ToString(sn) + " AND " + "       SaleKitChgTax.Line_No  = "
                                           + Convert.ToString(ln) + " AND " + "       SaleKitChgTax.Kit_Item = \'"
                                           + CommonUtility.GetStringValue(lineKit["Kit_Item"]) + "\' AND " + "       SaleKitChgTax.As_Code  = \'"
                                           + CommonUtility.GetStringValue(kitCharge["As_Code"]) + "\' ", db);

                    var cgt = new Charge_Taxes();
                    foreach (DataRow tax in rsCgt.Rows)
                    {
                        cgt.Add(CommonUtility.GetStringValue(tax["Tax_Name"]),
                                CommonUtility.GetStringValue(tax["Tax_Code"]),
                                CommonUtility.GetFloatValue(tax["Tax_Rate"]),
                                CommonUtility.GetBooleanValue(tax["Tax_Included"]), "");
                    }
                    lkc.Add(CommonUtility.GetDoubleValue(kitCharge["price"]),
                            CommonUtility.GetStringValue(kitCharge["Description"]),
                            CommonUtility.GetStringValue(kitCharge["As_Code"]), cgt, "");
                }

                lk.Add(CommonUtility.GetStringValue(lineKit["Kit_Item"]),
                       CommonUtility.GetStringValue(lineKit["Descript"]),
                       CommonUtility.GetFloatValue(lineKit["Quantity"]),
                       CommonUtility.GetFloatValue(lineKit["Base"]),
                       CommonUtility.GetFloatValue(lineKit["Fraction"]),
                       CommonUtility.GetFloatValue(lineKit["Alloc"]),
                       CommonUtility.GetStringValue(lineKit["Serial"]), lkc, "");
            }

            var returnValue = lk;

            return(returnValue);
        }
Exemple #12
0
        /// <summary>
        /// Method to get list of treaty numbers
        /// </summary>
        /// <param name="query">Query</param>
        /// <returns>List of treaty numbers</returns>
        public List <TreatyNo> GetTreatyNumbers(string query)
        {
            var oRecs = GetRecords(query, DataSource.CSCMaster);

            return((from DataRow treaty in oRecs.Rows
                    select new TreatyNo
            {
                TreatyNumber = CommonUtility.GetStringValue(treaty["TreatyNo"]),
                AltTreatyNo = CommonUtility.GetShortValue(treaty["AltTreatyNo"]),
                TobaccoQuota = CommonUtility.GetIntergerValue(treaty["TobaccoQuota"]),
                GasQuota = CommonUtility.GetFloatValue(treaty["GasQuota"]),
                TreatyName = CommonUtility.GetStringValue(treaty["TreatyName"])
            }).ToList());
        }
Exemple #13
0
        /// <summary>
        /// Method to get list of prices
        /// </summary>
        /// <param name="stockCode">Stock code</param>
        /// <returns>List of prices</returns>
        public List <PriceL> GetPriceL(string stockCode)
        {
            var rs = GetRecords("SELECT   *  FROM     Pricel  WHERE    Pricel.Stock_code = \'" + stockCode + "\' ORDER BY Pricel.Pr_F_Qty ", DataSource.CSCMaster);

            return((from DataRow dr in rs.Rows
                    select new PriceL
            {
                FQuantity = CommonUtility.GetFloatValue(dr["Pr_F_Qty"]),
                TQuantity = CommonUtility.GetFloatValue(dr["Pr_T_Qty"]),
                Price = CommonUtility.GetFloatValue(dr["Price"]),
                StartDate = CommonUtility.GetDateTimeValue(dr["StartDate"]),
                EndDate = CommonUtility.GetDateTimeValue(dr["EndDate"])
            }).ToList());
        }
        /// <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);
        }
        /// <summary>
        /// Method to get tax free price
        /// </summary>
        /// <param name="blForFuel">For fule price or not</param>
        /// <param name="sProductKey">Product key</param>
        /// <param name="stockcode">Stock code</param>
        /// <param name="quantityPerPkg">Quantity per kg</param>
        /// <param name="baseUnitQty">Base unit quantity</param>
        /// <param name="taxExemptTaxCode">tax code</param>
        /// <param name="productCode">Product code</param>
        /// <param name="eOutCategory">Category</param>
        /// <param name="dOutUnitsPerPkg">Units per kg</param>
        /// <param name="sOutUpcCode">Out up code</param>
        /// <param name="isError">Is error or not</param>
        /// <returns>True or false</returns>
        public bool TeGetTaxFreePriceByRate(bool blForFuel, ref string sProductKey, string stockcode,
                                            ref short quantityPerPkg, ref short baseUnitQty,
                                            ref short taxExemptTaxCode, ref string productCode,
                                            ref mPrivateGlobals.teProductEnum eOutCategory,
                                            ref float dOutUnitsPerPkg, ref string sOutUpcCode,
                                            out bool isError)
        {
            var dateStart = DateTime.Now;

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

            DataTable oRecs;

            if (blForFuel)
            {
                oRecs = GetRecords("SELECT CategoryFK,ProductCode,TAX_CODE,  QuantityPerPkg, BaseUnitQty,  1 As UnitsPerPkg, \'\' As UpcCode  from ProductTaxExempt Where ProductKey =\'" + stockcode + "\' ", DataSource.CSCMaster);
            }
            else
            {
                oRecs = GetRecords("SELECT CategoryFK, ProductCode,UnitsPerPkg, TAX_CODE, QuantityPerPkg, BaseUnitQty, UpcCode FROM ProductTaxExempt Where ProductKey=\'" + sProductKey + "\'", DataSource.CSCMaster);
            }
            if (oRecs.Rows.Count == 0)
            {
                isError = false;
                return(false);
            }

            taxExemptTaxCode = CommonUtility.GetShortValue(oRecs.Rows[0]["Tax_Code"]);
            productCode      = CommonUtility.GetStringValue(oRecs.Rows[0]["ProductCode"]);
            if (CommonUtility.GetBooleanValue(oRecs.Rows[0]["CategoryFK"]))
            {
                eOutCategory = (mPrivateGlobals.teProductEnum)CommonUtility.GetIntergerValue(oRecs.Rows[0]["CategoryFK"]);
            }
            else
            {
                isError = true;
                return(true);
            }
            isError         = false;
            dOutUnitsPerPkg = CommonUtility.GetFloatValue(oRecs.Rows[0]["UnitsPerPkg"]);
            sOutUpcCode     = CommonUtility.GetStringValue(oRecs.Rows[0]["UpcCode"]);
            quantityPerPkg  = CommonUtility.GetShortValue(oRecs.Rows[0]["QuantityPerPkg"]);
            baseUnitQty     = CommonUtility.GetShortValue(oRecs.Rows[0]["BaseUnitQty"]);
            _performancelog.Debug($"End,TaxService,TeGetTaxFreePriceByRate,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(true);
        }
Exemple #16
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>
        /// Method to get tax purchase item
        /// </summary>
        /// <param name="saleNo">Sale numvber</param>
        /// <param name="lineNo">Line number</param>
        /// <returns>Tax exempt purchase item</returns>
        public tePurchaseItem GetPurchaseItem(int saleNo, int lineNo)
        {
            tePurchaseItem teItem = null;
            var            rs     = GetRecords("select * from PurchaseItem where Sale_No=" + Convert.ToString(saleNo) + " AND Line_No=" + Convert.ToString(lineNo), DataSource.CSCTills);

            if (rs.Rows.Count > 0)
            {
                teItem                 = new tePurchaseItem();
                teItem.TreatyNo        = CommonUtility.GetStringValue(rs.Rows[0]["TreatyNo"]);
                teItem.PsTierID        = CommonUtility.GetShortValue(rs.Rows[0]["TierID"]);
                teItem.PsLevelID       = CommonUtility.GetShortValue(rs.Rows[0]["LevelID"]);
                teItem.PdOriginalPrice = CommonUtility.GetFloatValue(rs.Rows[0]["OriginalPrice"]);
                teItem.TaxFreePrice    = CommonUtility.GetFloatValue(rs.Rows[0]["Amount"]);
                teItem.petaxInclPrice  = -1 * CommonUtility.GetFloatValue(teItem.TaxFreePrice + CommonUtility.GetFloatValue(rs.Rows[0]["TotalTaxSaved"]));
            }
            return(teItem);
        }
        /// <summary>
        /// Method to get tax exempt tax free price by price
        /// </summary>
        /// <param name="sSql">Query</param>
        /// <param name="dOutPrice">Price</param>
        /// <param name="originalPrice">Original Price</param>
        /// <param name="eOutCategory">Category</param>
        /// <param name="dOutUnitsPerPkg">Units per kg</param>
        /// <param name="sOutUpcCode">UPC code</param>
        /// <param name="bFound">Found or not</param>
        /// <param name="isError">Error or not</param>
        /// <returns>True or false</returns>
        public bool TeGetTaxFreePriceByPrice(string sSql, ref float dOutPrice, double originalPrice,
                                             ref mPrivateGlobals.teProductEnum eOutCategory, ref float dOutUnitsPerPkg,
                                             ref string sOutUpcCode, out bool bFound,
                                             out bool isError)
        {
            var dateStart = DateTime.Now;

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

            var oRecs = GetRecords(sSql, DataSource.CSCPump);

            //eCategory and bFound are already set.
            if (oRecs.Rows.Count > 0)
            {
                if (CommonUtility.GetIntergerValue(oRecs.Rows[0]["TaxFreePrice"]) != 0)
                {
                    dOutPrice = CommonUtility.GetFloatValue(oRecs.Rows[0]["TaxFreePrice"]);
                }
                else
                {
                    dOutPrice = (float)originalPrice;
                }
                if (CommonUtility.GetBooleanValue(oRecs.Rows[0]["CategoryFK"]))
                {
                    eOutCategory = (mPrivateGlobals.teProductEnum)CommonUtility.GetIntergerValue(oRecs.Rows[0]["CategoryFK"]);
                }
                else
                {
                    isError = true;
                    bFound  = false;
                    return(false);
                }

                dOutUnitsPerPkg = CommonUtility.GetFloatValue(oRecs.Rows[0]["UnitsPerPkg"]);
                sOutUpcCode     = CommonUtility.GetStringValue(oRecs.Rows[0]["UpcCode"]);
                bFound          = true;
                isError         = false;
                return(true);
            }
            bFound  = false;
            isError = false;
            _performancelog.Debug($"End,TaxService,TeGetTaxFreePriceByPrice,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(false);
        }
        /// <summary>
        /// Method to get discount percent
        /// </summary>
        /// <param name = "productDiscount" > Product discount</param>
        /// <param name = "customerDiscount" > Customer discount</param>
        /// <returns>Discount percent</returns>
        public float?GetDiscountPercent(short productDiscount, short customerDiscount)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,UtilityService,GetDiscountPercent,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");
            float?discountpercentage = null;
            var   rs = GetRecords("Select * From   DiscTab  WHERE  DiscTab.Prod_Disc = "
                                  + Convert.ToString(productDiscount) + " AND " + "       DiscTab.Cust_Disc = "
                                  + Convert.ToString(customerDiscount) + " ", DataSource.CSCMaster);

            if (rs.Rows.Count > 0)
            {
                discountpercentage = CommonUtility.GetFloatValue(rs.Rows[0]["Disc_Perc"]);
            }
            _performancelog.Debug($"End,UtilityService,GetDiscountPercent,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(discountpercentage);
        }
        /// <summary>
        /// Get Bottle Returns to display on Main Grid
        /// </summary>
        /// <param name="startIndex">Start index</param>
        /// <param name="endIndex">End index</param>
        /// <returns>List of bottles</returns>
        public List <BottleReturn> GetBottlesFromDbMaster(int startIndex, int endIndex)
        {
            var dt            = GetRecords("SELECT *  FROM   HotButtons  WHERE  HotButtons.Button > " + (startIndex - 1) + " " + " AND  HotButtons.Button <" + (endIndex + 1) + "ORDER BY HotButtons.Button ", DataSource.CSCMaster);
            var bottleReturns = new List <BottleReturn>();

            foreach (DataRow dr in dt.Rows)
            {
                var bottleReturn = new BottleReturn
                {
                    Product     = CommonUtility.GetStringValue(dr["Product"]),
                    Image_Url   = CommonUtility.GetStringValue(dr["Image_Url"]),
                    Description = $"{CommonUtility.GetStringValue(dr["Description_1"])} {CommonUtility.GetStringValue(dr["Description_2"])}",
                    Price       = CommonUtility.GetFloatValue(dr["BottlePrice"]),
                    Quantity    = CommonUtility.GetFloatValue(dr["DefaultQty"])
                };
                bottleReturns.Add(bottleReturn);
            }
            return(bottleReturns);
        }
        /// <summary>
        /// Method to get tax exempt rate
        /// </summary>
        /// <param name="taxExemptTaxCode">Tax exempt tax code</param>
        /// <param name="taxRate">Tax rate</param>
        /// <param name="rateType">Rate type</param>
        /// <returns>True or false</returns>
        public bool GetTaxExemptRate(string taxExemptTaxCode, out float taxRate, out string rateType)
        {
            var dateStart = DateTime.Now;

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

            var rs = GetRecords("select * from TaxExemptRate where TAX_CODE=" + taxExemptTaxCode, DataSource.CSCMaster);

            if (rs.Rows.Count == 0)
            {
                taxRate  = 0;
                rateType = string.Empty;
                return(false);
            }

            taxRate  = CommonUtility.GetFloatValue(rs.Rows[0]["Tax_Rate"]);
            rateType = CommonUtility.GetStringValue(rs.Rows[0]["RateType"]);
            _performancelog.Debug($"End,TaxService,GetTaxExemptRate,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(true);
        }
Exemple #22
0
        /// <summary>
        /// Method to get line taxes
        /// </summary>
        /// <param name="saleNumber">Sale number</param>
        /// <param name="lineNumber">Line number</param>
        /// <param name="dataSource">Data source</param>
        /// <returns></returns>
        public List <Line_Tax> GetLineTaxes(int saleNumber, int lineNumber, DataSource dataSource)
        {
            var lineTaxes = new List <Line_Tax>();
            var rsLineTax = GetRecords("Select * From   S_LineTax  WHERE  S_LineTax.Sale_No = "
                                       + Convert.ToString(saleNumber) + " AND " + "       S_LineTax.Line_No = " + Convert.ToString(lineNumber)
                                       + " " + "Order By S_LineTax.Tax_Name ", dataSource);

            foreach (DataRow row in rsLineTax.Rows)
            {
                lineTaxes.Add(new Line_Tax
                {
                    Tax_Name        = CommonUtility.GetStringValue(row["Tax_Name"]),
                    Tax_Code        = CommonUtility.GetStringValue(row["Tax_Code"]),
                    Tax_Rate        = CommonUtility.GetFloatValue(row["Tax_Rate"]),
                    Tax_Included    = CommonUtility.GetBooleanValue(row["Tax_Included"]),
                    Tax_Rebate_Rate = CommonUtility.GetFloatValue(row["Tax_Rebate_Rate"]),
                    Tax_Rebate      = CommonUtility.GetDecimalValue(row["Tax_Rebate"])
                });
            }
            return(lineTaxes);
        }
        /// <summary>
        /// Method to get tax exempt card holder
        /// </summary>
        /// <param name="cardHolderId">card holder id</param>
        /// <returns>Tax exempt card holder</returns>
        public teCardholder GetTaxExemptCardHolder(string cardHolderId)
        {
            var dateStart = DateTime.Now;

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

            var rsCardHolder = GetRecords("select * from TaxExemptCardRegistry Where CardholderID= \'" + cardHolderId + "\'", DataSource.CSCMaster);

            if (rsCardHolder.Rows.Count > 0)
            {
                return(new teCardholder
                {
                    CardholderID = cardHolderId,
                    TobaccoQuota = CommonUtility.GetFloatValue(rsCardHolder.Rows[0]["TobaccoQuota"]),
                    GasQuota = CommonUtility.GetFloatValue(rsCardHolder.Rows[0]["GasQuota"]),
                    PropaneQuota = CommonUtility.GetFloatValue(rsCardHolder.Rows[0]["PropaneQuota"])
                });
            }
            _performancelog.Debug($"End,TaxService,GetTaxExemptCardHolder,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(null);
        }
Exemple #24
0
        /// <summary>
        /// Get purchase items
        /// </summary>
        /// <param name="db">Data source</param>
        /// <param name="saleNumber">Sale number</param>
        /// <returns>Purchase items</returns>
        public List <tePurchaseItem> GetPurchaseItems(DataSource db, int saleNumber)
        {
            var purchaseItems = new List <tePurchaseItem>();
            var rs            = GetRecords("select saleline.gradeid, purchaseitem.* from PurchaseItem  " + " INNER JOIN Saleline on Saleline.Sale_no = Purchaseitem.sale_No and Saleline.line_num = purchaseitem.line_no " + " where purchaseitem.Sale_No=" + Convert.ToString(saleNumber), db);

            foreach (DataRow row in rs.Rows)
            {
                purchaseItems.Add(new tePurchaseItem
                {
                    TreatyNo            = CommonUtility.GetStringValue(row["TreatyNo"]),
                    PsTierID            = CommonUtility.GetShortValue(row["TierID"]),
                    PsLevelID           = CommonUtility.GetShortValue(row["LevelID"]),
                    PsGradeIDpsTreatyNo = CommonUtility.GetShortValue(row["GradeID"]),
                    PdOriginalPrice     = CommonUtility.GetFloatValue(row["OriginalPrice"]),
                    TaxFreePrice        = CommonUtility.GetFloatValue(row["Amount"]),
                    pdTaxFreePrice      = CommonUtility.GetFloatValue(row["TotalTaxSaved"]),
                    Quantity            = CommonUtility.GetFloatValue(row["Quantity"]),
                    LineItem            = CommonUtility.GetShortValue(row["Line_No"]),
                    stockcode           = CommonUtility.GetStringValue(row["cscpurchaseitemkey"]),
                });
            }
            return(purchaseItems);
        }
        /// <summary>
        /// Method to update tax exempt sale
        /// </summary>
        /// <param name="taxExemptSale">Tax exempt sale</param>
        /// <param name="gasLessQuota">Gas less quota</param>
        /// <param name="propaneLessQuota">Propane less quota</param>
        /// <param name="tobaccoLessQuota">Tobacco less quota</param>
        public void UpdateSale(TaxExemptSale taxExemptSale, float gasLessQuota, float propaneLessQuota,
                               float tobaccoLessQuota)
        {
            Line_Tax lt = default(Line_Tax);

            _connection = new SqlConnection(GetConnectionString(DataSource.CSCTills));
            if (_connection.State == ConnectionState.Closed)
            {
                _connection.Open();
            }
            _dataTable = new DataTable();
            var query = "select * from TaxExemptSaleHead " + " where SALE_NO=" + Convert.ToString(taxExemptSale.Sale_Num) + " AND TILL_NUM=" + Convert.ToString(taxExemptSale.TillNumber);

            _adapter = new SqlDataAdapter(query, _connection);
            _adapter.Fill(_dataTable);

            if (_dataTable.Rows.Count != 0)
            {
                var rsTeSaleHead = _dataTable.Rows[0];
                rsTeSaleHead["SaleAmount"] = taxExemptSale.Amount;
                if (!taxExemptSale.GasOverLimit)
                {
                    rsTeSaleHead["GasReason"]       = "";
                    rsTeSaleHead["GasReasonDesp"]   = "";
                    rsTeSaleHead["GasReasonDetail"] = "";
                }
                if (!taxExemptSale.PropaneOverLimit)
                {
                    rsTeSaleHead["PropaneReason"]       = "";
                    rsTeSaleHead["PropaneReasonDesp"]   = "";
                    rsTeSaleHead["PropaneReasonDetail"] = "";
                }
                if (!taxExemptSale.TobaccoOverLimit)
                {
                    rsTeSaleHead["TobaccoReason"]       = "";
                    rsTeSaleHead["TobaccoReasonDesp"]   = "";
                    rsTeSaleHead["TobaccoReasonDetail"] = "";
                }

                rsTeSaleHead["TotalExemptedTax"] = taxExemptSale.TotalExemptedTax;
                SqlCommandBuilder builder = new SqlCommandBuilder(_adapter);
                _adapter.UpdateCommand = builder.GetUpdateCommand();
                _adapter.Update(_dataTable);
            }


            foreach (TaxExemptSaleLine tempLoopVarTesl in taxExemptSale.Te_Sale_Lines)
            {
                var tesl = tempLoopVarTesl;
                _dataTable = new DataTable();
                query      = "select * from TaxExemptSaleLine " + " where SALE_NO="
                             + Convert.ToString(taxExemptSale.Sale_Num) + " AND LINE_NUM="
                             + Convert.ToString(taxExemptSale.TillNumber) + " AND LINE_NUM="
                             + Convert.ToString(tesl.Line_Num);
                _adapter = new SqlDataAdapter(query, _connection);
                _adapter.Fill(_dataTable);
                if (_dataTable.Rows.Count != 0)
                {
                    var rsTeSaleLine = _dataTable.Rows[0];
                    rsTeSaleLine["Quantity"]          = tesl.Quantity;
                    rsTeSaleLine["EquvQuantity"]      = tesl.EquvQuantity;
                    rsTeSaleLine["TaxIncludedAmount"] = tesl.TaxInclPrice;
                    rsTeSaleLine["Amount"]            = tesl.Amount;
                    rsTeSaleLine["ExemptedTax"]       = tesl.ExemptedTax;
                    rsTeSaleLine["OverLimit"]         = tesl.OverLimit;
                    rsTeSaleLine["RunningQuota"]      = tesl.RunningQuota.ToString("#0.00");

                    if (tesl.StockIsChanged)
                    {
                        rsTeSaleLine["Stock_Code"]    = tesl.StockCode;
                        rsTeSaleLine["ProductType"]   = tesl.ProductType;
                        rsTeSaleLine["ProductCode"]   = tesl.ProductCode;
                        rsTeSaleLine["Description"]   = tesl.Description;
                        rsTeSaleLine["price"]         = tesl.TaxFreePrice;
                        rsTeSaleLine["OriginalPrice"] = tesl.OriginalPrice;
                    }
                    SqlCommandBuilder builder = new SqlCommandBuilder(_adapter);
                    _adapter.UpdateCommand = builder.GetUpdateCommand();
                    _adapter.Update(_dataTable);
                }
            }
            bool addNew;

            foreach (Sale_Tax tempLoopVarSx in taxExemptSale.TaxCredit)
            {
                var sx = tempLoopVarSx;
                if (sx.Taxable_Amount != 0 | sx.Tax_Included_Amount != 0)
                {
                    addNew     = false;
                    _dataTable = new DataTable();
                    query      = "SELECT * from TaxCredit where TILL_NUM=" + taxExemptSale.TillNumber
                                 + " AND SALE_NO=" + Convert.ToString(taxExemptSale.Sale_Num)
                                 + " AND Tax_Name=\'" + sx.Tax_Name + "\' AND " + " Tax_Code=\'"
                                 + sx.Tax_Code + "\' ";
                    _adapter = new SqlDataAdapter(query, _connection);
                    _adapter.Fill(_dataTable);
                    DataRow taxCredit;
                    if (_dataTable.Rows.Count == 0)
                    {
                        addNew                = true;
                        taxCredit             = _dataTable.NewRow();
                        taxCredit["Till_Num"] = taxExemptSale.TillNumber;
                        taxCredit["sale_no"]  = taxExemptSale.Sale_Num;
                        taxCredit["Tax_Name"] = sx.Tax_Name;
                        taxCredit["Tax_Code"] = sx.Tax_Code;
                        SqlCommandBuilder builder = new SqlCommandBuilder(_adapter);
                        _adapter.InsertCommand = builder.GetInsertCommand();
                    }
                    else
                    {
                        taxCredit = _dataTable.Rows[0];
                        SqlCommandBuilder builder = new SqlCommandBuilder(_adapter);
                        _adapter.UpdateCommand = builder.GetUpdateCommand();
                    }
                    taxCredit["Tax_Rate"]            = sx.Tax_Rate;
                    taxCredit["Taxable_Amount"]      = sx.Taxable_Amount;
                    taxCredit["Tax_Added_Amount"]    = sx.Tax_Added_Amount;
                    taxCredit["Tax_Included_Amount"] = sx.Tax_Included_Amount;
                    taxCredit["Tax_Included_Total"]  = sx.Tax_Included_Total;
                    if (addNew)
                    {
                        _dataTable.Rows.Add(taxCredit);
                    }
                    _adapter.Update(_dataTable);
                }
            }

            foreach (TaxCreditLine tempLoopVarTx in taxExemptSale.TaxCreditLines)
            {
                var tx = tempLoopVarTx;
                foreach (Line_Tax tempLoopVarLt in tx.Line_Taxes)
                {
                    addNew     = false;
                    _dataTable = new DataTable();
                    query      = "SELECT * from TaxCreditLine where TILL_NUM=" + taxExemptSale.TillNumber
                                 + " AND SALE_NO=" + Convert.ToString(taxExemptSale.Sale_Num) + " AND Tax_Name=\'"
                                 + lt.Tax_Name + "\' AND " + " Line_No=" + Convert.ToString(tx.Line_Num);
                    _adapter = new SqlDataAdapter(query, _connection);
                    _adapter.Fill(_dataTable);
                    DataRow taxCreditLine;
                    lt = tempLoopVarLt;
                    if (_dataTable.Rows.Count == 0)
                    {
                        addNew                    = true;
                        taxCreditLine             = _dataTable.NewRow();
                        taxCreditLine["Till_Num"] = taxExemptSale.TillNumber;
                        taxCreditLine["sale_no"]  = taxExemptSale.Sale_Num;
                        taxCreditLine["Line_No"]  = tx.Line_Num;
                        taxCreditLine["Tax_Name"] = lt.Tax_Name;
                        SqlCommandBuilder builder = new SqlCommandBuilder(_adapter);
                        _adapter.InsertCommand = builder.GetInsertCommand();
                    }
                    else
                    {
                        taxCreditLine = _dataTable.Rows[0];
                        SqlCommandBuilder builder = new SqlCommandBuilder(_adapter);
                        _adapter.UpdateCommand = builder.GetUpdateCommand();
                    }
                    taxCreditLine["Tax_Code"]            = lt.Tax_Code;
                    taxCreditLine["Tax_Rate"]            = lt.Tax_Rate;
                    taxCreditLine["Tax_Included"]        = lt.Tax_Included;
                    taxCreditLine["Tax_Added_Amount"]    = lt.Tax_Added_Amount;
                    taxCreditLine["Tax_Included_Amount"] = lt.Tax_Incl_Amount;
                    if (addNew)
                    {
                        _dataTable.Rows.Add(taxCreditLine);
                    }
                    _adapter.Update(_dataTable);
                }
            }
            _connection.Close();

            _connection = new SqlConnection(GetConnectionString(DataSource.CSCMaster));
            if (_connection.State == ConnectionState.Closed)
            {
                _connection.Open();
            }
            var rsCardHolder = new DataTable();

            query    = "select * from TaxExemptCardRegistry " + " where CardholderID=\'" + taxExemptSale.teCardholder.CardholderID + "\'";
            _adapter = new SqlDataAdapter(query, _connection);
            _adapter.Fill(_dataTable);
            if (rsCardHolder.Rows.Count != 0)
            {
                rsCardHolder.Rows[0]["TobaccoQuota"] = (CommonUtility.GetFloatValue(rsCardHolder.Rows[0]["TobaccoQuota"]) - tobaccoLessQuota).ToString("#0.00");
                rsCardHolder.Rows[0]["GasQuota"]     = (CommonUtility.GetFloatValue(rsCardHolder.Rows[0]["GasQuota"]) - gasLessQuota).ToString("#0.00");
                rsCardHolder.Rows[0]["PropaneQuota"] = (CommonUtility.GetFloatValue(rsCardHolder.Rows[0]["PropaneQuota"]) - propaneLessQuota).ToString("#0.00");
                SqlCommandBuilder builder = new SqlCommandBuilder(_adapter);
                _adapter.UpdateCommand = builder.GetUpdateCommand();
                _adapter.Update(rsCardHolder);
            }
            _connection.Close();
            _adapter?.Dispose();
        }
        /// <summary>
        /// Method to load tax exempt for delete preapay
        /// </summary>
        /// <param name="taxExemptSale">Tax exempt sale</param>
        /// <param name="teType">Tax exempt type</param>
        /// <param name="till">Till</param>
        /// <param name="user">User</param>
        /// <param name="sn">Sale number</param>
        /// <param name="tillId">Till number</param>
        /// <param name="lineNum">Line number</param>
        /// <param name="newSaleNo">New sale number</param>
        /// <returns>True or false</returns>
        public bool LoadTaxExemptForDeletePrepay(ref TaxExemptSale taxExemptSale,
                                                 string teType, Till till, User user, int sn, byte tillId, short lineNum,
                                                 int newSaleNo)
        {
            var rsHead = GetRecords("select * from TaxExemptSaleHead " + " where SALE_NO=" + Convert.ToString(sn) + " AND TILL_NUM=" + Convert.ToString(tillId), DataSource.CSCTills);
            var rsLine = GetRecords("select * from TaxExemptSaleLine " + " where SALE_NO=" + Convert.ToString(sn) + " AND LINE_NUM=" + Convert.ToString(lineNum) + " AND TILL_NUM=" + Convert.ToString(tillId), DataSource.CSCTills);

            if (teType == "QITE")
            {
                if (rsHead.Rows.Count == 0)
                {
                    return(false);
                }
            }
            else //
            {
                if (rsHead.Rows.Count == 0 || rsLine.Rows.Count == 0)
                {
                    return(false);
                }
            }


            taxExemptSale = new TaxExemptSale
            {
                Sale_Num     = newSaleNo,
                TillNumber   = tillId,
                Shift        = Convert.ToInt16(till.Shift),
                UserCode     = Convert.ToString(user.Code),
                teCardholder =
                {
                    CardholderID = CommonUtility.GetStringValue(rsHead.Rows[0]["CardholderID"]),
                    Barcode      = CommonUtility.GetStringValue(rsHead.Rows[0]["Barcode"]),
                    CardNumber   = CommonUtility.GetStringValue(rsHead.Rows[0]["cardnumber"])
                }
            };


            //ShinyFeb26,2009- QITE development
            if (teType == "QITE")
            {
                var rsCardHolder = GetRecords("select * from CLIENT " + " where CL_CODE=\'" + taxExemptSale.teCardholder.CardholderID + "\'", DataSource.CSCMaster);
                if (rsCardHolder.Rows.Count != 0)
                {
                    taxExemptSale.teCardholder.Name        = CommonUtility.GetStringValue(rsCardHolder.Rows[0]["Cl_Name"]);
                    taxExemptSale.teCardholder.Address     = CommonUtility.GetStringValue(rsCardHolder.Rows[0]["CL_Add1"]);
                    taxExemptSale.teCardholder.City        = CommonUtility.GetStringValue(rsCardHolder.Rows[0]["CL_City"]);
                    taxExemptSale.teCardholder.PlateNumber = CommonUtility.GetStringValue(rsCardHolder.Rows[0]["PlateNumber"]);
                    taxExemptSale.teCardholder.PostalCode  = CommonUtility.GetStringValue(rsCardHolder.Rows[0]["CL_Postal"]);
                }
                //
            }
            else // For AITE
            {
                var rsCardHolder = GetRecords("select * from TaxExemptCardRegistry " + " where CardholderID=\'" + taxExemptSale.teCardholder.CardholderID + "\'", DataSource.CSCMaster);
                if (rsCardHolder.Rows.Count != 0)
                {
                    taxExemptSale.teCardholder.Name         = CommonUtility.GetStringValue(rsCardHolder.Rows[0]["Name"]);
                    taxExemptSale.teCardholder.GasQuota     = CommonUtility.GetFloatValue(rsCardHolder.Rows[0]["GasQuota"]);
                    taxExemptSale.teCardholder.PropaneQuota = CommonUtility.GetFloatValue(rsCardHolder.Rows[0]["PropaneQuota"]);
                    taxExemptSale.teCardholder.TobaccoQuota = CommonUtility.GetFloatValue(rsCardHolder.Rows[0]["TobaccoQuota"]);
                }
            }
            if (rsLine.Rows.Count != 0)
            {
                foreach (DataRow line in rsLine.Rows)
                {
                    var mTeLine = new TaxExemptSaleLine
                    {
                        Quantity      = CommonUtility.GetFloatValue(-1 * CommonUtility.GetIntergerValue(line["Quantity"])),
                        UnitsPerPkg   = CommonUtility.GetFloatValue(-1 * CommonUtility.GetIntergerValue(line["UnitQuantity"])),
                        EquvQuantity  = CommonUtility.GetFloatValue(-1 * CommonUtility.GetIntergerValue(line["EquvQuantity"])),
                        OriginalPrice = CommonUtility.GetFloatValue(line["OriginalPrice"]),
                        TaxFreePrice  = CommonUtility.GetFloatValue(line["price"]),
                        Line_Num      = 1,
                        StockCode     = CommonUtility.GetStringValue(line["Stock_Code"]),
                        TaxInclPrice  = CommonUtility.GetFloatValue(-1 * CommonUtility.GetIntergerValue(line["TaxIncludedAmount"])),
                        Amount        = CommonUtility.GetFloatValue(-1 * CommonUtility.GetIntergerValue(line["Amount"])),
                        ExemptedTax   = CommonUtility.GetFloatValue(-1 * CommonUtility.GetIntergerValue(line["ExemptedTax"])),
                        Description   = CommonUtility.GetStringValue(line["Description"]),
                        ProductCode   = CommonUtility.GetStringValue(line["ProductCode"])
                    };

                    mPrivateGlobals.teProductEnum productType;
                    Enum.TryParse(CommonUtility.GetStringValue(line["ProductType"]), out productType);

                    mTeLine.ProductType = productType;

                    mTeLine.TaxExemptRate = CommonUtility.GetFloatValue(line["TaxExemptRate"]);

                    bool tempCheckOverLimit = true;
                    var  tempCheckQuota     = true;
                    taxExemptSale.Add_a_Line(mTeLine, ref tempCheckOverLimit, ref tempCheckQuota);
                }
            }

            taxExemptSale.Amount = CommonUtility.GetFloatValue(-1 * CommonUtility.GetIntergerValue(rsHead.Rows[0]["SaleAmount"]));

            LoadGstExemptForDeletePrepay(ref taxExemptSale, sn, tillId, DataSource.CSCTills);
            return(true);
        }
        /// <summary>
        /// Method to load tax exempt
        /// </summary>
        /// <param name="teType">Tax exemption type</param>
        /// <param name="sn">Sale number</param>
        /// <param name="tillId">Till Number</param>
        /// <param name="db">Data base</param>
        /// <param name="checkQuota">Check Quota or not</param>
        /// <returns>Tax exempt sale</returns>
        public TaxExemptSale LoadTaxExempt(string teType, int sn, byte tillId, DataSource db,
                                           bool checkQuota = true)
        {
            var taxExemptSale = new TaxExemptSale();

            if (LoadGstExempt(ref taxExemptSale, sn, tillId, db))
            {
                taxExemptSale.Sale_Num   = sn;
                taxExemptSale.TillNumber = tillId;
            }

            var rsHead = GetRecords("select * from TaxExemptSaleHead " + " where SALE_NO=" + Convert.ToString(sn) + " AND TILL_NUM=" + Convert.ToString(tillId), db);
            var rsLine = GetRecords("select * from TaxExemptSaleLine " + " where SALE_NO=" + Convert.ToString(sn) + " AND TILL_NUM=" + Convert.ToString(tillId), db);

            if (teType == "QITE")
            {
                if (rsHead.Rows.Count == 0)
                {
                    return(null);
                }
            }
            else
            {
                if (rsHead.Rows.Count == 0 || rsLine.Rows.Count == 0)
                {
                    return(null);
                }
            }
            var rsHeadField = rsHead.Rows[0];

            taxExemptSale.Sale_Num   = sn;
            taxExemptSale.TillNumber = tillId;

            foreach (DataRow fields in rsLine.Rows)
            {
                var mTeLine = new TaxExemptSaleLine
                {
                    Quantity      = CommonUtility.GetFloatValue(fields["Quantity"]),
                    UnitsPerPkg   = CommonUtility.GetFloatValue(fields["UnitQuantity"]),
                    EquvQuantity  = CommonUtility.GetFloatValue(fields["EquvQuantity"]),
                    OriginalPrice = CommonUtility.GetFloatValue(fields["OriginalPrice"]),
                    TaxFreePrice  = CommonUtility.GetFloatValue(fields["price"]),
                    Line_Num      = CommonUtility.GetShortValue(fields["Line_Num"]),
                    StockCode     = CommonUtility.GetStringValue(fields["Stock_Code"]),
                    TaxInclPrice  = CommonUtility.GetFloatValue(fields["TaxIncludedAmount"]),
                    Amount        = CommonUtility.GetFloatValue(fields["Amount"]),
                    ExemptedTax   = CommonUtility.GetFloatValue(fields["ExemptedTax"]),
                    Description   = CommonUtility.GetStringValue(fields["Description"]),
                    ProductCode   = CommonUtility.GetStringValue(fields["ProductCode"])
                };
                mPrivateGlobals.teProductEnum productType;
                Enum.TryParse(CommonUtility.GetStringValue(fields["ProductType"]), out productType);
                mTeLine.ProductType  = productType;
                mTeLine.RunningQuota = CommonUtility.GetFloatValue(fields["RunningQuota"]);

                mTeLine.OverLimit = CommonUtility.GetBooleanValue(fields["OverLimit"]);

                mTeLine.TaxExemptRate = CommonUtility.GetFloatValue(fields["TaxExemptRate"]);
                var tempCheckOverLimit = false;
                taxExemptSale.Add_a_Line(mTeLine, ref tempCheckOverLimit, ref checkQuota);
                if (!mTeLine.OverLimit)
                {
                    continue;
                }
                switch (mTeLine.ProductType)
                {
                case mPrivateGlobals.teProductEnum.eCigarette:
                case mPrivateGlobals.teProductEnum.eCigar:
                case mPrivateGlobals.teProductEnum.eLooseTobacco:
                    taxExemptSale.TobaccoOverLimit = true;
                    break;

                case mPrivateGlobals.teProductEnum.eGasoline:
                case mPrivateGlobals.teProductEnum.eDiesel:
                case mPrivateGlobals.teProductEnum.emarkedGas:
                case mPrivateGlobals.teProductEnum.emarkedDiesel:

                    taxExemptSale.GasOverLimit = true;
                    break;

                case mPrivateGlobals.teProductEnum.ePropane:
                    taxExemptSale.PropaneOverLimit = true;
                    break;

                case mPrivateGlobals.teProductEnum.eNone:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            taxExemptSale.Amount              = CommonUtility.GetFloatValue(rsHeadField["SaleAmount"]);
            taxExemptSale.ShiftDate           = CommonUtility.GetDateTimeValue(rsHeadField["ShiftDate"]);
            taxExemptSale.Sale_Time           = CommonUtility.GetDateTimeValue(rsHeadField["SaleTime"]);
            taxExemptSale.GasReason           = CommonUtility.GetStringValue(rsHeadField["GasReason"]);
            taxExemptSale.GasReasonDesp       = CommonUtility.GetStringValue(rsHeadField["GasReasonDesp"]);
            taxExemptSale.GasReasonDetail     = CommonUtility.GetStringValue(rsHeadField["GasReasonDetail"]);
            taxExemptSale.PropaneReason       = CommonUtility.GetStringValue(rsHeadField["PropaneReason"]);
            taxExemptSale.PropaneReasonDesp   = CommonUtility.GetStringValue(rsHeadField["PropaneReasonDesp"]);
            taxExemptSale.PropaneReasonDetail = CommonUtility.GetStringValue(rsHeadField["PropaneReasonDetail"]);
            taxExemptSale.TobaccoReason       = CommonUtility.GetStringValue(rsHeadField["TobaccoReason"]);
            taxExemptSale.TobaccoReasonDesp   = CommonUtility.GetStringValue(rsHeadField["TobaccoReasonDesp"]);
            taxExemptSale.TobaccoReasonDetail = CommonUtility.GetStringValue(rsHeadField["TobaccoReasonDetail"]);
            taxExemptSale.Shift    = CommonUtility.GetShortValue(rsHeadField["Shift"]);
            taxExemptSale.UserCode = CommonUtility.GetStringValue(rsHeadField["User"]);
            taxExemptSale.teCardholder.CardholderID = CommonUtility.GetStringValue(rsHeadField["CardholderID"]);
            taxExemptSale.teCardholder.Barcode      = CommonUtility.GetStringValue(rsHeadField["Barcode"]);
            taxExemptSale.teCardholder.CardNumber   = CommonUtility.GetStringValue(rsHeadField["cardnumber"]);
            if (teType == "QITE")
            {
                var rsCardHolder = GetRecords("select * from CLIENT " + " where CL_CODE=\'" + taxExemptSale.teCardholder.CardholderID + "\'", DataSource.CSCMaster);
                if (rsCardHolder.Rows.Count > 0)
                {
                    taxExemptSale.teCardholder.Name        = CommonUtility.GetStringValue(rsCardHolder.Rows[0]["Cl_Name"]);
                    taxExemptSale.teCardholder.Address     = CommonUtility.GetStringValue(rsCardHolder.Rows[0]["CL_Add1"]);
                    taxExemptSale.teCardholder.City        = CommonUtility.GetStringValue(rsCardHolder.Rows[0]["CL_City"]);
                    taxExemptSale.teCardholder.PlateNumber = CommonUtility.GetStringValue(rsCardHolder.Rows[0]["PlateNumber"]);
                    taxExemptSale.teCardholder.PostalCode  = CommonUtility.GetStringValue(rsCardHolder.Rows[0]["CL_Postal"]);
                }
            }
            else // For AITE
            {
                var rsCardHolder = GetRecords("select * from TaxExemptCardRegistry " + " where CardholderID=\'" + taxExemptSale.teCardholder.CardholderID + "\'", DataSource.CSCMaster);
                if (rsCardHolder.Rows.Count > 0)
                {
                    taxExemptSale.teCardholder.Name = CommonUtility.GetStringValue(rsCardHolder.Rows[0]["Name"]);
                }
            }
            return(taxExemptSale);
        }
        /// <summary>
        /// Method to save tax exempt sale head
        /// </summary>
        /// <param name="oteSale">Tax exempt sale</param>
        /// <param name="shiftDate">Shift date</param>
        public void SaveTaxExemptSaleHead(TaxExemptSale oteSale, DateTime shiftDate)
        {
            _connection = new SqlConnection(GetConnectionString(DataSource.CSCTills));
            if (_connection.State == ConnectionState.Closed)
            {
                _connection.Open();
            }
            bool addNew = false;


            _dataTable = new DataTable();
            var query = "select * from TaxExemptSaleHead " + " where SALE_NO=" + Convert.ToString(oteSale.Sale_Num) +
                        " AND TILL_NUM=" + Convert.ToString(oteSale.TillNumber);

            _adapter = new SqlDataAdapter(query, _connection);
            _adapter.Fill(_dataTable);
            DataRow rsTeSaleHead;

            if (_dataTable.Rows.Count == 0)
            {
                rsTeSaleHead             = _dataTable.NewRow();
                rsTeSaleHead["sale_no"]  = oteSale.Sale_Num;
                rsTeSaleHead["Till_Num"] = oteSale.TillNumber;
                addNew = true;
                SqlCommandBuilder builder = new SqlCommandBuilder(_adapter);
                _adapter.InsertCommand = builder.GetInsertCommand();
            }
            else
            {
                rsTeSaleHead = _dataTable.Rows[0];
                SqlCommandBuilder builder = new SqlCommandBuilder(_adapter);
                _adapter.UpdateCommand = builder.GetUpdateCommand();
            }
            rsTeSaleHead["Shift"]               = oteSale.Shift;
            rsTeSaleHead["User"]                = oteSale.UserCode;
            rsTeSaleHead["CardholderID"]        = oteSale.teCardholder.CardholderID;
            rsTeSaleHead["Barcode"]             = oteSale.teCardholder.Barcode;
            rsTeSaleHead["cardnumber"]          = oteSale.teCardholder.CardNumber;
            rsTeSaleHead["ShiftDate"]           = shiftDate;
            rsTeSaleHead["SaleTime"]            = oteSale.Sale_Time; // Now
            rsTeSaleHead["SaleAmount"]          = oteSale.Amount;
            rsTeSaleHead["SaleLines"]           = oteSale.Te_Sale_Lines.Count;
            rsTeSaleHead["GasReason"]           = oteSale.GasReason;
            rsTeSaleHead["GasReasonDesp"]       = oteSale.GasReasonDesp;
            rsTeSaleHead["GasReasonDetail"]     = oteSale.GasReasonDetail;
            rsTeSaleHead["PropaneReason"]       = oteSale.PropaneReason;
            rsTeSaleHead["PropaneReasonDesp"]   = oteSale.PropaneReasonDesp;
            rsTeSaleHead["PropaneReasonDetail"] = oteSale.PropaneReasonDetail;
            rsTeSaleHead["TobaccoReason"]       = oteSale.TobaccoReason;
            rsTeSaleHead["TobaccoReasonDesp"]   = oteSale.TobaccoReasonDesp;
            rsTeSaleHead["TobaccoReasonDetail"] = oteSale.TobaccoReasonDetail;
            rsTeSaleHead["TotalExemptedTax"]    = oteSale.TotalExemptedTax;
            if (addNew)
            {
                _dataTable.Rows.Add(rsTeSaleHead);
            }
            _adapter.Update(_dataTable);

            foreach (TaxExemptSaleLine tempLoopVarTesl in oteSale.Te_Sale_Lines)
            {
                addNew = false;
                var tesl = tempLoopVarTesl;
                _dataTable = new DataTable();
                query      = "select * from TaxExemptSaleLine where SALE_NO=" + Convert.ToString(oteSale.Sale_Num)
                             + " AND Till_NUM=" + Convert.ToString(oteSale.TillNumber) + " AND LINE_NUM="
                             + Convert.ToString(tesl.Line_Num);
                _adapter = new SqlDataAdapter(query, _connection);
                _adapter.Fill(_dataTable);
                DataRow rsTeSaleLine;
                if (_dataTable.Rows.Count == 0)
                {
                    rsTeSaleLine             = _dataTable.NewRow();
                    rsTeSaleLine["Till_Num"] = oteSale.TillNumber;
                    rsTeSaleLine["sale_no"]  = oteSale.Sale_Num;
                    rsTeSaleLine["Line_Num"] = tesl.Line_Num;
                    addNew = true;
                    SqlCommandBuilder builder = new SqlCommandBuilder(_adapter);
                    _adapter.InsertCommand = builder.GetInsertCommand();
                }
                else
                {
                    rsTeSaleLine = _dataTable.Rows[0];
                    SqlCommandBuilder builder = new SqlCommandBuilder(_adapter);
                    _adapter.UpdateCommand = builder.GetUpdateCommand();
                }
                rsTeSaleLine["Stock_Code"]        = tesl.StockCode;
                rsTeSaleLine["ProductType"]       = tesl.ProductType;
                rsTeSaleLine["ProductCode"]       = tesl.ProductCode;
                rsTeSaleLine["Description"]       = tesl.Description;
                rsTeSaleLine["Quantity"]          = tesl.Quantity;
                rsTeSaleLine["UnitQuantity"]      = tesl.UnitsPerPkg;
                rsTeSaleLine["EquvQuantity"]      = tesl.EquvQuantity;
                rsTeSaleLine["price"]             = tesl.TaxFreePrice;
                rsTeSaleLine["OriginalPrice"]     = tesl.OriginalPrice;
                rsTeSaleLine["TaxIncludedAmount"] = tesl.TaxInclPrice;
                rsTeSaleLine["Amount"]            = tesl.Amount;
                rsTeSaleLine["ExemptedTax"]       = tesl.ExemptedTax;
                rsTeSaleLine["RunningQuota"]      = tesl.RunningQuota;
                rsTeSaleLine["OverLimit"]         = tesl.OverLimit;
                rsTeSaleLine["TaxExemptRate"]     = tesl.TaxExemptRate;
                if (addNew)
                {
                    _dataTable.Rows.Add(rsTeSaleLine);
                }
                _adapter.Update(_dataTable);
            }
            _connection.Close();
            _adapter?.Dispose();

            _connection = new SqlConnection(GetConnectionString(DataSource.CSCMaster));
            if (_connection.State == ConnectionState.Closed)
            {
                _connection.Open();
            }
            query = "select * from TaxExemptCardRegistry " + " where CardholderID=\'" +
                    oteSale.teCardholder.CardholderID + "\'";

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

            if (taxExemptRegistry.Rows.Count != 0)
            {
                var rsCardHolder = taxExemptRegistry.Rows[0];
                var tobaccoQuota =
                    CommonUtility.GetFloatValue(CommonUtility.GetFloatValue(rsCardHolder["TobaccoQuota"]) +
                                                oteSale.TotalExemptTobacco).ToString("#0.00");
                var gasQuota =
                    CommonUtility.GetFloatValue(CommonUtility.GetFloatValue(rsCardHolder["GasQuota"]) + oteSale.TotalExemptGas)
                    .ToString("#0.00");
                var propaneQuota =
                    CommonUtility.GetFloatValue(CommonUtility.GetFloatValue(rsCardHolder["PropaneQuota"]) +
                                                oteSale.TotalExemptPropane)
                    .ToString("#0.00");
                var updateCommand =
                    $"update TaxExemptCardRegistry set TobaccoQuota= {tobaccoQuota}, GasQuota = {gasQuota}, PropaneQuota = {propaneQuota} where CardholderID='{oteSale.teCardholder.CardholderID}'";
                Execute(updateCommand, DataSource.CSCMaster);
            }
        }
        /// <summary>
        /// Method to get card holder
        /// </summary>
        /// <param name="isBarCode">Is bar code or not</param>
        /// <param name="strNumber">Number</param>
        /// <param name="matchCount">Match count</param>
        /// <param name="ageRestrict">Age restriction</param>
        /// <returns>Tax exempt card holder</returns>
        public teCardholder GetCardHolder(bool isBarCode, string strNumber, out short matchCount, int ageRestrict)
        {
            var dateStart = DateTime.Now;

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

            string       strSql;
            teCardholder cardHolder = new teCardholder {
                IsValidCardHolder = false
            };

            if (isBarCode)
            {
                strSql = "Select * from TaxExemptCardRegistry where BarCode=\'" + strNumber + "\'  OR AltBarCode=\'" + strNumber + "\'";
            }
            else
            {
                strSql = "Select * from TaxExemptCardRegistry where CardNumber=\'" + strNumber + "\'  OR AltCardNumber=\'" + strNumber + "\'";
            }
            var dt = GetRecords(strSql, DataSource.CSCMaster);

            matchCount = 0;
            if (dt != null && dt.Rows.Count > 0)
            {
                matchCount = Convert.ToInt16(dt.Rows.Count);
                if (matchCount > 1)
                {
                    cardHolder.IsValidCardHolder = false;
                    return(cardHolder);
                }

                DateTime mBirthDate;
                if (CommonUtility.GetBooleanValue(dt.Rows[0]["Birthdate"]))
                {
                    mBirthDate = DateAndTime.DateAdd(DateInterval.Year, Convert.ToDouble(-1 * (ageRestrict + 1)), DateAndTime.Today);
                }
                else
                {
                    mBirthDate = CommonUtility.GetDateTimeValue(dt.Rows[0]["Birthdate"]);
                }
                cardHolder.Birthdate = mBirthDate;


                cardHolder.Name              = CommonUtility.GetStringValue(dt.Rows[0]["Name"]);
                cardHolder.CardholderID      = CommonUtility.GetStringValue(dt.Rows[0]["CardholderID"]);
                cardHolder.IsValidCardHolder = false;
                if (isBarCode)
                {
                    if (CommonUtility.GetStringValue(dt.Rows[0]["Barcode"]) == strNumber)
                    {
                        cardHolder.ValidateMode = 1;
                        cardHolder.CardNumber   = CommonUtility.GetStringValue(dt.Rows[0]["CardNumber"]);
                    }
                    else
                    {
                        cardHolder.ValidateMode = 2;
                        cardHolder.CardNumber   = CommonUtility.GetStringValue(dt.Rows[0]["AltCardNumber"]);
                    }
                    cardHolder.Barcode = strNumber;
                }
                else
                {
                    if (CommonUtility.GetStringValue(dt.Rows[0]["CardNumber"]) == strNumber)
                    {
                        cardHolder.ValidateMode = 3;
                        cardHolder.Barcode      = CommonUtility.GetStringValue(dt.Rows[0]["Barcode"]);
                    }
                    else
                    {
                        cardHolder.ValidateMode = 4;
                        cardHolder.Barcode      = CommonUtility.GetStringValue(dt.Rows[0]["AltBarCode"]);
                    }
                    cardHolder.CardNumber = strNumber;
                }
                cardHolder.GasQuota          = CommonUtility.GetFloatValue(dt.Rows[0]["GasQuota"]);
                cardHolder.PropaneQuota      = CommonUtility.GetFloatValue(dt.Rows[0]["PropaneQuota"]);
                cardHolder.TobaccoQuota      = CommonUtility.GetFloatValue(dt.Rows[0]["TobaccoQuota"]);
                cardHolder.IsValidCardHolder = true;
            }
            _performancelog.Debug($"End,CustomerService,GetCardHolder,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");

            return(cardHolder);
        }
        /// <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);
        }