/// <summary> /// Get value of a specific individual /// </summary> /// <returns>value</returns> public AnimalPriceGroup GetPriceGroupOfIndividual(Ruminant ind, PurchaseOrSalePricingStyleType purchaseStyle, string warningMessage = "") { if (PricingAvailable()) { AnimalPriceGroup animalPrice = (purchaseStyle == PurchaseOrSalePricingStyleType.Purchase) ? ind.CurrentPriceGroups.Buy : ind.CurrentPriceGroups.Sell; if (animalPrice == null || !animalPrice.Filter(ind)) { // search through RuminantPriceGroups for first match with desired purchase or sale flag foreach (AnimalPriceGroup priceGroup in priceGroups.Where(a => a.PurchaseOrSale == purchaseStyle || a.PurchaseOrSale == PurchaseOrSalePricingStyleType.Both)) { if (priceGroup.Filter(ind)) { if (purchaseStyle == PurchaseOrSalePricingStyleType.Purchase) { ind.CurrentPriceGroups = (priceGroup, ind.CurrentPriceGroups.Sell); return(priceGroup); } else { ind.CurrentPriceGroups = (ind.CurrentPriceGroups.Buy, priceGroup); return(priceGroup); } } } // no price match found. string warningString = warningMessage; if (warningString == "") { warningString = $"No [{purchaseStyle}] price entry was found for [r={ind.Breed}] meeting the required criteria [f=age: {ind.Age}] [f=sex: {ind.Sex}] [f=weight: {ind.Weight:##0}]"; } Warnings.CheckAndWrite(warningString, Summary, this, MessageType.Warning); } return(animalPrice); } return(null); }
/// <summary> /// Get value of a specific individual with special requirements check (e.g. breeding sire or draught purchase) /// </summary> /// <returns>value</returns> public AnimalPriceGroup GetPriceGroupOfIndividual(Ruminant ind, PurchaseOrSalePricingStyleType purchaseStyle, string property, string value, string warningMessage = "") { double price = 0; if (PricingAvailable()) { AnimalPriceGroup animalPrice = (purchaseStyle == PurchaseOrSalePricingStyleType.Purchase) ? ind.CurrentPriceGroups.Buy : ind.CurrentPriceGroups.Sell; if (animalPrice == null || !animalPrice.Filter(ind)) { string criteria = property.ToUpper() + ":" + value.ToUpper(); //find first pricing entry matching specific criteria AnimalPriceGroup matchIndividual = null; AnimalPriceGroup matchCriteria = null; var priceGroups = PriceList.FindAllChildren <AnimalPriceGroup>() .Where(a => a.PurchaseOrSale == purchaseStyle || a.PurchaseOrSale == PurchaseOrSalePricingStyleType.Both); foreach (AnimalPriceGroup priceGroup in priceGroups) { if (priceGroup.Filter(ind) && matchIndividual == null) { matchIndividual = priceGroup; } var suitableFilters = priceGroup.FindAllChildren <FilterByProperty>() .Where(a => (a.PropertyOfIndividual == property) & ( (a.Operator == System.Linq.Expressions.ExpressionType.Equal && a.Value.ToString().ToUpper() == value.ToUpper()) | (a.Operator == System.Linq.Expressions.ExpressionType.NotEqual && a.Value.ToString().ToUpper() != value.ToUpper()) | (a.Operator == System.Linq.Expressions.ExpressionType.IsTrue && value.ToUpper() == "TRUE") | (a.Operator == System.Linq.Expressions.ExpressionType.IsFalse && value.ToUpper() == "FALSE") ) ).Any(); // check that pricing item meets the specified criteria. if (suitableFilters) { if (matchCriteria == null) { matchCriteria = priceGroup; } else // multiple price entries were found. using first. value = xxx. if (!warningsMultipleEntry.Contains(criteria)) { warningsMultipleEntry.Add(criteria); Summary.WriteMessage(this, "Multiple specific [" + purchaseStyle.ToString() + "] price entries were found for [r=" + ind.Breed + "] where [" + property + "]" + (value.ToUpper() != "TRUE" ? " = [" + value + "]." : ".") + "\r\nOnly the first entry will be used. Price [" + matchCriteria.Value.ToString("#,##0.##") + "] [" + matchCriteria.PricingStyle.ToString() + "].", MessageType.Warning); } } } if (matchCriteria == null) { string warningString = warningMessage; if (warningString != "") { // no warning string passed to method so calculate one // report specific criteria not found in price list warningString = "No [" + purchaseStyle.ToString() + "] price entry was found for [r=" + ind.Breed + "] meeting the required criteria [" + property + "]" + (value.ToUpper() != "TRUE" ? " = [" + value + "]." : "."); if (matchIndividual != null) { // add using the best pricing available for [][] purchases of xx per head warningString += "\r\nThe best available price [" + matchIndividual.Value.ToString("#,##0.##") + "] [" + matchIndividual.PricingStyle.ToString() + "] will be used."; price = matchIndividual.Value * ((matchIndividual.PricingStyle == PricingStyleType.perKg) ? ind.Weight : 1.0); } else { warningString += "\r\nNo alternate price for individuals could be found for the individuals. Add a new [r=AnimalPriceGroup] entry in the [r=AnimalPricing] for [" + ind.Breed + "]"; } } if (!warningsNotFound.Contains(criteria)) { warningsNotFound.Add(criteria); Summary.WriteMessage(this, warningString, MessageType.Warning); } } if (purchaseStyle == PurchaseOrSalePricingStyleType.Purchase) { ind.CurrentPriceGroups = (matchCriteria, ind.CurrentPriceGroups.Sell); return(matchCriteria); } else { ind.CurrentPriceGroups = (ind.CurrentPriceGroups.Buy, matchCriteria); return(matchCriteria); } } } return(null); }