/// <summary>
        /// Get Quota
        /// </summary>
        /// <param name="treatyNo">Treaty number</param>
        /// <param name="eProdType">Product type</param>
        /// <param name="dOutQuota">Quota</param>
        /// <returns>True or false</returns>
        public bool GetQuota(ref teTreatyNo treatyNo, ref mPrivateGlobals.teProductEnum eProdType,
                             ref double dOutQuota)
        {
            treatyNo.CheckInit();

            //   for real time validation SITE and Jan 12, 2015 for FNGTR validation this validation not required
            //   moved in processing sale to display the remaining qty
            if (_policyManager.SITE_RTVAL || _policyManager.TAX_EXEMPT_FNGTR)
            {
                return(true);
            }
            //   end

            var sFieldName = GetQuotaField(eProdType);

            dOutQuota = _treatyService.GetQuota(sFieldName, treatyNo.TreatyNumber);


            if (_policyManager.TE_Type != "SITE")
            {
                return(true);
            }
            if (eProdType == mPrivateGlobals.teProductEnum.eCigar | eProdType == mPrivateGlobals.teProductEnum.eLooseTobacco)
            {
                dOutQuota = dOutQuota * _teSystemManager.GetCigaretteEquivalentUnits((mPrivateGlobals.teTobaccoEnum)System.Convert.ToInt16(eProdType));
            }
            return(true);
        }
 //Name: Init
 //Description: Used to initialize the class with a Treaty Number.  The treaty
 // number can be valid or invalid.  Invalid treaty numbers are permitted because
 // the system is supposed to allow cashiers to provide tax exempt purchases
 // for invalid treaty numbers at their own risk.
 //Inputs:
 // sTreatyNo: the Treaty Number used with this class.  May be a valid treaty
 //    number or it may be garbage.  This conforms to the Sask Fin spec.
 // bSwiped: True if the treaty number was swiped, false if it was keyed in.
 //Note: In the original design, if swiped is True, the sTreatyNo parameter
 // will be treated as "alternate purchase identifier" and the actual TreatyNo
 // will be looked up in a table.
 //Note: In the current version this method will always return True.  Should there
 // be a requirements change to deny tax exempt purchases to invalid treaty numbers
 //(as originally specified), this method will return false if the treaty number is
 // invalid.  Until that time, it will always return True.
 /// <summary>
 /// Method to initialise treaty number
 /// </summary>
 /// <param name="treatyNo">Treaty number</param>
 /// <param name="sTreatyNo">Treaty value</param>
 /// <param name="bSwiped">Swiped or not</param>
 /// <returns>True or false</returns>
 public bool Init(ref teTreatyNo treatyNo, string sTreatyNo, bool bSwiped)
 {
     treatyNo.TreatyNumber = sTreatyNo;
     treatyNo.isSwiped     = bSwiped;
     treatyNo.IsInit       = true;
     treatyNo.Name         = _treatyService.GetTreatyName(sTreatyNo);
     return(treatyNo.IsInit);
 }
        //Name: AddToQuota
        //Description: Adds the given quantity to the purchaser's current quota.  This
        // function will take care of cigarette equivalency math, the caller only
        // needs to enter the quantity sold.  For example, if a 30g pouch of tobacco
        // is sold, this function will look up the cigarette equivalency and do the
        // appropriate conversion internally.
        //Inputs: eProdType, the product type that was sold.
        //   dQuantity: The amount sold, grams for tobacco, number of cigarettes, number
        //      of cigars or number of liters of fuel.
        //Outputs: Returns True if function worked ok.  If False, check GetLastError()
        //Postconditions: On success, the appropriate amount will be added to the person's
        //   quota.  Note, all cigartte equivalency conversions are done internally.
        /// <summary>
        /// Method to add to quota
        /// </summary>
        /// <param name="treatyNo">Treaty umber</param>
        /// <param name="eProdType">Product type</param>
        /// <param name="dQuantity">Quantity</param>
        /// <returns>True or false</returns>
        public bool AddToQuota(teTreatyNo treatyNo, ref mPrivateGlobals.teProductEnum eProdType, double dQuantity)
        {
            treatyNo.CheckInit();
            if (string.IsNullOrEmpty(treatyNo.GetTreatyNo()))
            {
                return(false);
            }

            var dConvertedQuantity = dQuantity;

            if (eProdType == mPrivateGlobals.teProductEnum.eCigar | eProdType == mPrivateGlobals.teProductEnum.eLooseTobacco)
            {
                dConvertedQuantity = dConvertedQuantity * mPrivateGlobals.theSystem.teGetCigaretteEquivalentUnits((mPrivateGlobals.teTobaccoEnum)System.Convert.ToInt16(eProdType));
            }

            //Check if an entry in TreatyNo exists for this person.
            var sSql = "SELECT * FROM TreatyNo WHERE TreatyNo=\'" + treatyNo.GetTreatyNo() + "\'";

            var oRecs = _treatyService.GetTreatyNumbers(sSql);

            var sField = GetQuotaField(eProdType);

            if (oRecs.Count == 0)
            {
                //Record does not exist, so insert a new one
                //  New info - Treaty name

                //      "VALUES ('" & psTreatyNo & "', " & dConvertedQuantity & ")"
                sSql = "INSERT INTO TreatyNo ( TreatyNo, " + sField + ",TreatyName ) " + "VALUES (\'" + treatyNo.GetTreatyNo() + "\', " + System.Convert.ToString(dConvertedQuantity) + ", \'" + treatyNo.Name + "\')";
                //shiny end
            }
            else
            {
                foreach (var treaty in oRecs)
                {
                    if (treaty.TreatyNumber != treatyNo.GetTreatyNo())
                    {
                        continue;
                    }


                    double quantity = sField == "TobaccoQuota" ? treaty.TobaccoQuota : treaty.GasQuota;
                    dConvertedQuantity = System.Convert.ToDouble(dConvertedQuantity + quantity);

                    goto resumeOutofLoop;
                }

resumeOutofLoop:
                //Record exists, so update the current quota with the new value
                //  Update Treaty name

                sSql = "UPDATE TreatyNo " + "SET " + sField + "=" + (dConvertedQuantity) + " " + " , TreatyName =\'" + treatyNo.Name + "\'  WHERE TreatyNo=\'" + treatyNo.GetTreatyNo() + "\'";
            }
            _treatyService.UpdateTreatyNumber(sSql);

            return(true);
        }
        /// <summary>
        /// Method to load tax exempt prepay
        /// </summary>
        /// <param name="saleNo">Sale number</param>
        /// <param name="sl">Sale line</param>
        /// <param name="lineNo">Line number</param>
        /// <param name="sale">Sale</param>
        /// <param name="oPurchaseList">Purchase list</param>
        /// <param name="oTreatyNo">Treaty number</param>
        /// <returns>True or false</returns>
        public bool LoadTaxExemptPrepay(int saleNo, Sale_Line sl, short lineNo, ref
                                        Sale sale, ref tePurchaseList oPurchaseList, ref teTreatyNo oTreatyNo)
        {
            var returnValue = false;

            if (!_policyManager.TAX_EXEMPT)
            {
                return(false);
            }
            var user = CacheManager.GetUser(UserCode);

            if (_policyManager.TE_Type == "SITE")
            {
                var teItem = _taxExemptSaleService.GetPurchaseItem(saleNo, lineNo);
                if (teItem != null)
                {
                    _treatyManager.Init(ref oTreatyNo, teItem.TreatyNo, false);
                    oPurchaseList.Init(oTreatyNo, sale.Sale_Num, sale.TillNumber);

                    var    tempSProductKey  = mPrivateGlobals.theSystem.teMakeFuelKey(sl.GradeID, teItem.PsTierID, teItem.PsLevelID);
                    var    tempIsFuelItem   = true;
                    var    stockCode        = string.Empty;
                    short  iRowNumberinSale = 0;
                    double tempQuantity     = 0f;
                    double org           = teItem.PdOriginalPrice;
                    double taxIncldPrice = teItem.petaxInclPrice;
                    _purchaseListManager.AddItem(ref oPurchaseList,
                                                 ref sale, ref oTreatyNo, ref tempSProductKey, ref tempQuantity, ref org, ref iRowNumberinSale, ref stockCode, ref taxIncldPrice, ref tempIsFuelItem);
                    sl.Stock_Code = stockCode;
                }
            }
            else
            {
                var oTeSale = new TaxExemptSale();

                if (_taxExemptSaleService.LoadTaxExemptForDeletePrepay(ref oTeSale,
                                                                       _policyManager.TE_Type, _tillService.GetTill(sale.TillNumber),
                                                                       user, saleNo, sale.TillNumber, lineNo, sale.Sale_Num))
                {
                    returnValue = true;
                }
                else if (_taxExemptSaleService.LoadGstExemptForDeletePrepay(ref oTeSale,
                                                                            saleNo, sale.TillNumber, DataSource.CSCTills))
                {
                    oTeSale.teCardholder.GstExempt = true;
                }
            }
            return(returnValue);
        }
        /// <summary>
        /// Method to set remaining fuel quantity
        /// </summary>
        /// <param name="treatyNo">Treaty number</param>
        /// <param name="oPurchaseList">Purchase list</param>
        /// <param name="sale">Sale</param>
        /// <param name="remainingFuelQuantity">Remaining fuel quantity</param>
        public void SetRemainingFuelQuantity(ref teTreatyNo treatyNo, ref tePurchaseList oPurchaseList, ref Sale sale, double remainingFuelQuantity)
        {
            //  set which items in the purchase list require override
            treatyNo.RemainingFuelQuantity = remainingFuelQuantity;
            short index;
            var   productType = default(mPrivateGlobals.teProductEnum);

            var runningQuota = remainingFuelQuantity;

            for (index = oPurchaseList.Count(); index >= 1; index--)
            {
                oPurchaseList.Item(index).GetProductType(ref productType);
                if (
                    !(productType == mPrivateGlobals.teProductEnum.eGasoline |
                      productType == mPrivateGlobals.teProductEnum.eDiesel |
                      productType == mPrivateGlobals.teProductEnum.ePropane |
                      productType == mPrivateGlobals.teProductEnum.emarkedGas |
                      productType == mPrivateGlobals.teProductEnum.emarkedDiesel))
                {
                    continue;
                }
                double dblTempQty = oPurchaseList.Item(index).Quantity *oPurchaseList.Item(index).UnitsPerPkg *oPurchaseList.Item(index).ItemEquivalence;
                if (dblTempQty <= runningQuota)
                {
                    oPurchaseList.Item(index).OverrideRequired = false;
                    treatyNo.ValidTreatyNo    = true;
                    treatyNo.OverrideRequired = false;
                }
                else
                {
                    oPurchaseList.Item(index).OverrideRequired = true;
                    treatyNo.OverrideRequired = true;
                    if (!treatyNo.ValidTreatyNo)
                    {
                        treatyNo.ValidTreatyNo = false;
                    }
                    var rowNumber = oPurchaseList.Item(index).GetRowInSalesMain();
                    sale.Sale_Lines[rowNumber].IsTaxExemptItem = false;
                    sale.Sale_Lines[rowNumber].overrideCode    = 0;
                    oPurchaseList.RemoveItem(index);
                }
                runningQuota = runningQuota - dblTempQty;
            }
            //   end
        }
示例#6
0
        /// <summary>
        /// Add Item to Purchase List
        /// </summary>
        /// <param name="purchaseList">Purchase list</param>
        /// <param name="sale">Sale</param>
        /// <param name="peTreatyNo">Treaty number</param>
        /// <param name="sProductKey">Product key</param>
        /// <param name="dQuantity">Quantity</param>
        /// <param name="dOriginalPrice">Original price</param>
        /// <param name="iRowNumberInSalesMainForm">Row number</param>
        /// <param name="stockcode">Stock code</param>
        /// <param name="taxInclPrice">Tax included price</param>
        /// <param name="isFuelItem">Is fuel item or not</param>
        /// <returns>True or false</returns>
        public bool AddItem(ref tePurchaseList purchaseList, ref Sale sale,
                            ref teTreatyNo peTreatyNo, ref string sProductKey, ref double dQuantity,
                            ref double dOriginalPrice, ref short iRowNumberInSalesMainForm,
                            ref string stockcode, ref double taxInclPrice, ref bool isFuelItem)
        {
            double quota              = 0;
            var    productType        = default(mPrivateGlobals.teProductEnum);
            var    limitMaxType       = default(mPrivateGlobals.teLimitEnum);
            var    limitThresholdType = default(mPrivateGlobals.teLimitEnum);
            double limitMax           = 0;
            double limitThreshold     = 0;
            short  ret;
            string formatString  = "";
            double runningQuotaF = 0;
            short  runningQuotaT = 0;

            var oItem = new tePurchaseItem {
                BIsInit = true
            };

            //initialize item then add to purchase list
            if (!_purchaseItemManager.Init(ref oItem, ref peTreatyNo, ref sProductKey, dOriginalPrice, dQuantity, iRowNumberInSalesMainForm, sale.Sale_Num, sale.TillNumber, ref stockcode, taxInclPrice, isFuelItem, purchaseList.NoRTVP))
            {
                purchaseList.SetLastError(mPrivateGlobals.theSystem.teGetLastError());//"Failed to Add Item: " & oDb.GetLastError()
                return(false);
            }

            oItem.GetProductType(ref productType);

            // Validation
            if (_policyManager.SITE_RTVAL && !purchaseList.NoRTVP) // And Not Me.NoRTVP
            {
                if (productType == mPrivateGlobals.teProductEnum.eCigarette | productType == mPrivateGlobals.teProductEnum.eCigar | productType == mPrivateGlobals.teProductEnum.eLooseTobacco)
                {
                    ret = Convert.ToInt16(Variables.RTVPService.SetItemUPC(oItem.LineItem, sProductKey, (int)productType));
                    WriteToLogFile("Response is " + Convert.ToString(ret) + " from SetItemUPC sent with parameters " + Convert.ToString(oItem.LineItem) + "," + sProductKey + "," + Convert.ToString(productType));
                    formatString = "0.00";
                }
                else
                {
                    SetStockCode(ref oItem, stockcode);
                    ret = Convert.ToInt16(Variables.RTVPService.SetItemUPC(oItem.LineItem, oItem.ItemUPC, (int)productType));
                    WriteToLogFile("Response is " + Convert.ToString(ret) + " from SetItemUPC sent with parameters " + Convert.ToString(oItem.LineItem) + "," + oItem.ItemUPC + "," + Convert.ToString(productType));
                    formatString = "0.000";
                }
                if (ret != 0)
                {
                    purchaseList.RTVPCommand  = "SetItemUPC";
                    purchaseList.RTVPError    = true;
                    purchaseList.RTVPResponse = ret;
                    return(false);
                }
                purchaseList.RTVPError = false;

                ret = Convert.ToInt16(Variables.RTVPService.SetItemTotal(oItem.LineItem,
                                                                         double.Parse((dQuantity * oItem.GetTaxFreePrice()).ToString(formatString))));
                WriteToLogFile("Response is " + Convert.ToString(ret) + " from SetItemTotal sent with parameters " + Convert.ToString(oItem.LineItem) + "," +
                               (dQuantity * oItem.GetTaxFreePrice()).ToString(formatString));
                if (ret != 0)
                {
                    purchaseList.RTVPCommand  = "SetItemTotal";
                    purchaseList.RTVPError    = true;
                    purchaseList.RTVPResponse = ret;
                    return(false);
                }
                purchaseList.RTVPError = false;
            }
            //   end

            var unitsPerPkg = oItem.UnitsPerPkg;
            var quantity    = dQuantity * unitsPerPkg;

            // validation
            if (_policyManager.SITE_RTVAL && !purchaseList.NoRTVP) // And Not Me.NoRTVP
            {
                // based on email from SITE all products need SetItemEquivalence including fuel
                // for fuel we decided to set Equivalence to 1, meaning send the quantity
                double dblEquivalent;
                if (productType == mPrivateGlobals.teProductEnum.eCigarette | productType == mPrivateGlobals.teProductEnum.eCigar | productType == mPrivateGlobals.teProductEnum.eLooseTobacco)
                {
                    dblEquivalent = _teSystemManager.GetCigaretteEquivalentUnits((mPrivateGlobals.teTobaccoEnum)Convert.ToInt16(productType));
                }
                else
                {
                    dblEquivalent = 1;
                }
                oItem.Quantity        = (float)dQuantity;     //
                oItem.ItemEquivalence = (float)dblEquivalent; //
                oItem.UnitsPerPkg     = unitsPerPkg;

                ret = Convert.ToInt16(Variables.RTVPService.SetItemEquivalence(oItem.LineItem, double.Parse((quantity * dblEquivalent).ToString(formatString))));
                WriteToLogFile("Response is " + Convert.ToString(ret) + " from SetItemEquivalence sent with parameters " + Convert.ToString(oItem.LineItem) + "," +
                               (quantity * dblEquivalent).ToString(formatString));
                if (ret != 0)
                {
                    purchaseList.RTVPCommand  = "SetItemEquivalence";
                    purchaseList.RTVPError    = true;
                    purchaseList.RTVPResponse = ret;
                    return(false);
                }
                purchaseList.RTVPError = false;
            }
            else
            {
                _treatyManager.GetQuota(ref peTreatyNo, ref productType, ref quota);
            }

            //   added the If condition; real time validation for SITE doesn't require next code
            if (!_policyManager.SITE_RTVAL)
            {
                GetLimitType(productType, ref limitMaxType, ref limitThresholdType);
                _teSystemManager.TeGetLimit(limitMaxType, ref limitMax);
                _teSystemManager.TeGetLimit(limitThresholdType, ref limitThreshold);

                if (productType == mPrivateGlobals.teProductEnum.eGasoline | productType == mPrivateGlobals.teProductEnum.eDiesel | productType == mPrivateGlobals.teProductEnum.ePropane | productType == mPrivateGlobals.teProductEnum.emarkedGas | productType == mPrivateGlobals.teProductEnum.emarkedDiesel) // hen
                {
                    runningQuotaF = (float)(runningQuotaF + quantity + quota);

                    //   added next two lines, for FNGTR Gasoline Single Transaction Limit is the only validation required
                    if (_policyManager.TAX_EXEMPT_FNGTR)
                    {
                        if (runningQuotaF > limitMax)
                        {
                            purchaseList.IsFuelOverLimit = true;
                        }
                        else
                        {
                            purchaseList.IsTobaccoOverLimit = false;
                        }
                        purchaseList.IsTobaccoOverLimit = false;
                    }
                    else
                    {
                        if (runningQuotaF > limitThreshold)
                        {
                            purchaseList.IsFuelOverLimit = true;
                        }
                        else if (quantity > limitMax)
                        {
                            purchaseList.IsFuelOverLimit = true;
                        }
                        else
                        {
                            purchaseList.IsFuelOverLimit = false;
                        }
                    }
                    if (!_teSystemManager.IsLimitRequired(ref mPrivateGlobals.theSystem, productType))
                    {
                        purchaseList.IsFuelOverLimit = false;
                    }
                }
                else if (productType == mPrivateGlobals.teProductEnum.eCigarette | productType == mPrivateGlobals.teProductEnum.eCigar | productType == mPrivateGlobals.teProductEnum.eLooseTobacco)
                {
                    runningQuotaT = (short)(runningQuotaT + quantity + quota);

                    if (runningQuotaT > limitThreshold)
                    {
                        purchaseList.IsTobaccoOverLimit = true;
                    }
                    else if (runningQuotaT > limitMax)
                    {
                        purchaseList.IsTobaccoOverLimit = true;
                    }
                    else
                    {
                        purchaseList.IsTobaccoOverLimit = false;
                    }



                    if (!_teSystemManager.IsLimitRequired(ref mPrivateGlobals.theSystem, productType))
                    {
                        purchaseList.IsTobaccoOverLimit = false;
                    }
                }
            }
            // real time validation end if '

            purchaseList.AddItemInCollection(oItem); //save the item in purchase list



            purchaseList.PeQuantity   = quantity;
            purchaseList.PsProductKey = sProductKey;
            return(true);
        }
示例#7
0
        public tePurchaseList GetPurchaseList(int saleNumber, int tillNumber, string userCode, string treatyNumber, string treatyName, out ErrorMessage error)
        {
            var sale      = _saleManager.GetCurrentSale(saleNumber, tillNumber, 0, userCode, out error);
            var oTreatyNo = new teTreatyNo()
            {
                TreatyNumber = treatyNumber, Name = treatyName
            };

            var    offSet         = _policyManager.LoadStoreInfo().OffSet;
            double originalPrice  = 0;
            double taxIncldAmount = 0;

            sale.TreatyNumber = oTreatyNo.TreatyNumber;
            sale.TreatyName   = oTreatyNo.Name;

            error = null;

            var oPurchaseList = new tePurchaseList();

            oPurchaseList.Init(oTreatyNo, sale.Sale_Num, sale.TillNumber);

            var y = oPurchaseList.GetTreatyNo();

            foreach (Sale_Line tempLoopVarSl in sale.Sale_Lines)
            {
                var    sl = tempLoopVarSl;
                string strError;

                if (sl.Amount < 0 && sl.IsTaxExemptItem)
                {
                    taxIncldAmount = -1 * sl.TaxInclPrice;
                    //shiny - Dec9, 2009 - Squamish nation
                    //                OriginalPrice = sl.Regular_Price

                    if (_policyManager.TE_ByRate == false) // Regualr Site customers SITE , TE_By rate = no
                    {
                        originalPrice = sl.Regular_Price;  //  - editing the price for TE is keeping different price in purchaseitem and saleline'SL.price
                    }
                    else if (_policyManager.TE_ByRate)     //squamish SITE , TE_By rate = yes
                    {
                        originalPrice = sl.price;
                    }
                }
                else
                {
                    //shiny - Dec9, 2009 - Squamish nation
                    //                OriginalPrice = sl.Regular_Price

                    if (_policyManager.TE_ByRate == false) // Regualr Site customers SITE , TE_By rate = no
                    {
                        originalPrice = sl.Regular_Price;  //  - editing the price for TE is keeping different price in purchaseitem and saleline'SL.price
                    }
                    else if (_policyManager.TE_ByRate)     //squamish SITE , TE_By rate = yes
                    {
                        originalPrice = sl.price;
                    }
                }



                if (sl.ProductIsFuel && !sl.IsPropane)
                {
                    if (_policyManager.USE_FUEL)
                    {
                        if (Variables.gPumps == null)
                        {
                            Variables.gPumps = _fuelPumpService.InitializeGetProperty(PosId, _policyManager.TAX_EXEMPT, _policyManager.TE_ByRate, _policyManager.TE_Type, _policyManager.AuthPumpPOS);
                        }
                        string tempSProductKey = _teSystemManager.TeMakeFuelKey(sl.GradeID, Convert.ToInt16(Variables.gPumps.get_Pump(sl.pumpID).TierID), Convert.ToInt16(Variables.gPumps.get_Pump(sl.pumpID).LevelID));
                        double tempDQuantity   = sl.Quantity;
                        var    tempIRowNumberInSalesMainForm = sl.Line_Num;
                        bool   tempIsFuelItem = true;
                        string tempStockCode  = sl.Stock_Code;
                        if (!AddItem(ref oPurchaseList, ref sale, ref oTreatyNo, ref tempSProductKey, ref tempDQuantity, ref originalPrice, ref tempIRowNumberInSalesMainForm, ref tempStockCode, ref taxIncldAmount, ref tempIsFuelItem))
                        {
                            strError = oPurchaseList.GetLastError();
                            if (strError == "2")
                            {
                                //MsgBox ("Cannot load Tax Exempt price, Please set Tax Exempt Category for Grade-" & SL.GradeID & " first in the BackOffice system! ")
                                //_resourceManager.CreateMessage(offSet,this, 17, temp_VbStyle, sl.GradeID, 0);
                                error = new ErrorMessage
                                {
                                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 17, sl.GradeID, CriticalOkMessageType),
                                    StatusCode   = HttpStatusCode.Conflict
                                };
                                return(null);
                            }
                            if (!string.IsNullOrEmpty(strError) && strError.ToUpper() != "NO ERROR")
                            {
                                //MsgBox ("Error(" & strError & ") for getting Tax Exempt price, will use original price for this sale!")
                                //_resourceManager.CreateMessage(offSet,this, 18, temp_VbStyle2, strError, 0);
                                error = new ErrorMessage
                                {
                                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 18, strError, CriticalOkMessageType),
                                    StatusCode   = HttpStatusCode.Conflict
                                };
                                return(null);
                            }
                            break;
                        }
                    }
                    else
                    {
                        var    tempSProductKey2 = sl.Stock_Code;
                        double tempDQuantity2   = sl.Quantity;
                        var    tempIRowNumberInSalesMainForm2 = sl.Line_Num;
                        bool   tempIsFuelItem2 = false;
                        var    tempStockCode   = sl.Stock_Code;
                        if (!AddItem(ref oPurchaseList, ref sale, ref oTreatyNo, ref tempSProductKey2, ref tempDQuantity2, ref originalPrice, ref tempIRowNumberInSalesMainForm2, ref tempStockCode, ref taxIncldAmount, ref tempIsFuelItem2))
                        {
                            strError = oPurchaseList.GetLastError();
                            if (!string.IsNullOrEmpty(strError) && strError.ToUpper() != "NO ERROR")
                            {
                                //_resourceManager.CreateMessage(offSet,this, 18, temp_VbStyle3, strError, 0);
                                error = new ErrorMessage
                                {
                                    MessageStyle = _resourceManager.CreateMessage(offSet, 11, 18, strError, CriticalOkMessageType),
                                    StatusCode   = HttpStatusCode.Conflict
                                };
                                return(null);
                            }
                        }
                    }
                }
                else
                {
                    var    tempSProductKey3 = sl.Stock_Code;
                    double tempDQuantity3   = sl.Quantity;
                    short  tempIRowNumberInSalesMainForm3 = sl.Line_Num;
                    bool   tempIsFuelItem3 = false;
                    var    tempStockCode   = sl.Stock_Code;
                    if (!AddItem(ref oPurchaseList, ref sale, ref oTreatyNo, ref tempSProductKey3, ref tempDQuantity3, ref originalPrice, ref tempIRowNumberInSalesMainForm3, ref tempStockCode, ref taxIncldAmount, ref tempIsFuelItem3))
                    {
                        strError = oPurchaseList.GetLastError();
                        if (!string.IsNullOrEmpty(strError) && strError.ToUpper() != "NO ERROR")
                        {
                            //_resourceManager.CreateMessage(offSet,this, 18, temp_VbStyle4, strError, 0);
                            error = new ErrorMessage
                            {
                                MessageStyle = _resourceManager.CreateMessage(offSet, 11, 18, strError, CriticalOkMessageType),
                                StatusCode   = HttpStatusCode.Conflict
                            };
                            return(null);
                        }
                    }
                }
            }

            var x = oPurchaseList.GetTreatyNo();

            CacheManager.AddPurchaseListSaleForTill(tillNumber, saleNumber, oPurchaseList);
            return(oPurchaseList);
        }
        /// <summary>
        /// Method to initiliase purchase item
        /// </summary>
        /// <param name="purchaseItem">Purchase item</param>
        /// <param name="oTreatyNo">Treaty number</param>
        /// <param name="sProductKey">Product key</param>
        /// <param name="dOriginalPrice">Original price</param>
        /// <param name="dQuantity">Orginal quantity</param>
        /// <param name="iRowNumberInSalesMainForm">Row number is sale line</param>
        /// <param name="invoiceId">Invoice Id</param>
        /// <param name="tillId">Till Id</param>
        /// <param name="stockcode">Stock code</param>
        /// <param name="taxInclPrice">Tax included price</param>
        /// <param name="isFuelItem">Is fuel item or not</param>
        /// <param name="noRtvp">RTVP or not</param>
        /// <returns>True or false</returns>
        public bool Init(ref tePurchaseItem purchaseItem, ref teTreatyNo oTreatyNo,
                         ref string sProductKey, double dOriginalPrice, double dQuantity,
                         short iRowNumberInSalesMainForm, int invoiceId, short tillId, ref string stockcode,
                         double taxInclPrice, bool isFuelItem, bool noRtvp)
        {
            purchaseItem.InvoiceID = invoiceId;
            purchaseItem.TillID    = tillId;

            if (!_teSystemManager.TeGetTaxFreePrice(ref mPrivateGlobals.theSystem, ref purchaseItem, sProductKey, (float)dOriginalPrice, false, stockcode, "", 0))
            {
                return(false);
            }

            if (_policyManager.SITE_RTVAL && !noRtvp) //   And Not NoRTVP condition
            {
                if (Variables.RTVPService == null)
                {
                    Variables.RTVPService = new RTVP.POSService.Transaction(); // Writing this to solve the issue of products not getting added in DB in tax exempt sale due to cache loss
                }
                purchaseItem.LineItem = Convert.ToInt16(Variables.RTVPService.AddLineItem());
                WriteToLogFile("Response is " + Convert.ToString(purchaseItem.LineItem) + " from AddLineItem sent with no parameters");
            }
            purchaseItem.Quantity = (float)dQuantity; //

            if (isFuelItem)
            {
                purchaseItem.PsIsFuelItem     = true;
                purchaseItem.PsGradeStockCode = stockcode;
                var psGradeId = purchaseItem.PsGradeIDpsTreatyNo;
                var psTierId  = purchaseItem.PsTierID;
                var psLevelId = purchaseItem.PsLevelID;
                _teSystemManager.TeExtractFuelKey(ref mPrivateGlobals.theSystem, ref sProductKey, ref psGradeId, ref psTierId, ref psLevelId);
                purchaseItem.PsGradeIDpsTreatyNo = psGradeId;
                purchaseItem.PsTierID            = psTierId;
                purchaseItem.PsLevelID           = psLevelId;
            }
            else
            {
                purchaseItem.PsIsFuelItem = false;
            }

            purchaseItem.PsProductKey     = sProductKey;
            purchaseItem.PdQuantity       = (float)dQuantity;
            purchaseItem.PiRowInSalesMain = iRowNumberInSalesMainForm;
            purchaseItem.PetaxInclPrice   = (float)dOriginalPrice;

            purchaseItem.PdOriginalPrice = (float)dOriginalPrice;

            purchaseItem.PiOverrideCode       = -1;
            purchaseItem.PsOverrideFormNumber = (0).ToString();

            purchaseItem.PsOverrideDetails = "Not Set";

            purchaseItem.PetaxInclPrice = (float)taxInclPrice;

            purchaseItem.PsTreatyNo = oTreatyNo;

            purchaseItem.BIsInit = true;
            if (!_policyManager.SITE_RTVAL)
            {
                purchaseItem.PeIsLimitRequired = _teSystemManager.IsLimitRequired(ref mPrivateGlobals.theSystem, purchaseItem.ProdType);
            }
            return(true);
        }