/// <summary> /// Used to Update Article Bag Price Properties, Prices, Totals etc, All Other Fields that not are Sent via Key and Props /// </summary> /// <param name="pKey"></param> /// <param name="pProps"></param> /// <returns></returns> public void UpdateKeyProperties(ArticleBagKey pKey) { bool debug = false; //Get Fresh PriceProperties Helper Object to Calc PriceProperties priceProperties = PriceProperties.GetPriceProperties( PricePropertiesSourceMode.FromPriceNet, false, pKey.Price, this[pKey].Quantity, pKey.Discount, this._discountGlobal, pKey.Vat ); this[pKey].PriceWithDiscount = priceProperties.PriceWithDiscount; this[pKey].PriceWithDiscountGlobal = priceProperties.PriceWithDiscountGlobal; this[pKey].TotalGross = priceProperties.TotalGross; this[pKey].TotalNet = priceProperties.TotalNet; this[pKey].TotalDiscount = priceProperties.TotalDiscount; this[pKey].TotalTax = priceProperties.TotalTax; this[pKey].TotalFinal = priceProperties.TotalFinal; this[pKey].PriceFinal = priceProperties.PriceFinal; if (debug) { priceProperties.SendToLog(""); _log.Debug(string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}", this[pKey].Code, pKey.Designation, this[pKey].Quantity, this[pKey].TotalGross, this[pKey].PriceWithDiscount, this[pKey].PriceWithDiscountGlobal, this[pKey].TotalGross, this[pKey].TotalNet, this[pKey].TotalDiscount, this[pKey].TotalTax, this[pKey].TotalFinal)); } }
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //Add From ArticleBag Key/Props //NEW: Override/Replace Dictionary Add with() Custom Add() new public void Add(ArticleBagKey pKey, ArticleBagProperties pProps) { //Init local vars ArticleBagKey key = pKey; ArticleBagProperties props = pProps; //Get Fresh PriceProperties Helper Object to used for Addition (Vat and Totals) PriceProperties addPriceProperties = PriceProperties.GetPriceProperties( PricePropertiesSourceMode.FromPriceNet, false, pKey.Price, pProps.Quantity, pKey.Discount, this._discountGlobal, pKey.Vat ); //If Key doesnt exists Add it if (!this.ContainsKey(key)) { base.Add(key, props); } //Else Update Key, Increase Quantity else { this[key].Quantity += props.Quantity; } //Refresh Current Key Price Properties after Add Quantity) UpdateKeyProperties(key); //TaxBag Add Key if (!_taxBag.ContainsKey(key.Vat)) { //Get Designation from Key //Get VatRate formated for filter, in sql server gives error without this it filters 23,0000 and not 23.0000 resulting in null vatRate string sql = string.Format("SELECT Designation FROM fin_configurationvatrate WHERE VALUE = '{0}'", FrameworkUtils.DecimalToString(key.Vat, GlobalFramework.CurrentCultureNumberFormat)); string designation = GlobalFramework.SessionXpo.ExecuteScalar(sql).ToString(); //Now Add New Key with Designation _taxBag.Add(key.Vat, new TaxBagProperties(designation, addPriceProperties.TotalTax, addPriceProperties.TotalNet)); } //Update Key, Add Vat else { _taxBag[key.Vat].Total += addPriceProperties.TotalTax; _taxBag[key.Vat].TotalBase += addPriceProperties.TotalNet; } _totalQuantity += addPriceProperties.Quantity; _totalNet += addPriceProperties.TotalNet; _totalGross += addPriceProperties.TotalGross; _totalTax += addPriceProperties.TotalTax; _totalDiscount += addPriceProperties.TotalDiscount; _totalFinal += addPriceProperties.TotalFinal; }
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //Used to Remove PartialPayments from ArticleBag public void Remove(ArticleBagKey pKey, decimal pRemoveQuantity) { //Get PriceProperties Helper Object to Remove from current Key PriceProperties removePriceProperties = PriceProperties.GetPriceProperties( PricePropertiesSourceMode.FromPriceNet, false, pKey.Price, pRemoveQuantity, pKey.Discount, this._discountGlobal, pKey.Vat ); //Decrease Quantity this[pKey].Quantity -= pRemoveQuantity; // SplitPayment : Sometimes we get 0.000000000000001, that makes key dont be removed because its not < 0 // To prevent this we must round value before compare using DecimalFormatStockQuantity string roundedFormat = $"{{0:{SettingsApp.DecimalFormatStockQuantity}}}";//{0:0.00000000} decimal roundedQuantity = Convert.ToDecimal(string.Format(roundedFormat, this[pKey].Quantity)); //if (this[pKey].Quantity <= 0) if (roundedQuantity <= 0) { this.Remove(pKey); } else { //Refresh Current Key Price Properties after Add Quantity) UpdateKeyProperties(pKey); } //Calc Article Grand Totals _totalQuantity -= removePriceProperties.Quantity; _totalNet -= removePriceProperties.TotalNet; _totalGross -= removePriceProperties.TotalGross; _totalTax -= removePriceProperties.TotalTax; _totalDiscount -= removePriceProperties.TotalDiscount; _totalFinal -= removePriceProperties.TotalFinal; //TaxBag Update _taxBag[pKey.Vat].Total -= removePriceProperties.TotalTax; _taxBag[pKey.Vat].TotalBase -= removePriceProperties.TotalNet; }