示例#1
0
文件: Labour.cs 项目: her123/ApsimX
        /// <summary>
        /// Get value of a specific individual with special requirements check (e.g. breeding sire or draught purchase)
        /// </summary>
        /// <returns>value</returns>
        public double PayRate(LabourType ind, LabourFilterParameters property, string value)
        {
            double price = 0;

            if (PricingAvailable)
            {
                string            criteria   = property.ToString().ToUpper() + ":" + value.ToUpper();
                List <LabourType> labourList = new List <LabourType>()
                {
                    ind
                };

                //find first pricing entry matching specific criteria
                LabourPriceGroup matchIndividual = null;
                LabourPriceGroup matchCriteria   = null;
                foreach (LabourPriceGroup item in PayList.FindAllChildren <LabourPriceGroup>().Cast <LabourPriceGroup>())
                {
                    if (labourList.Filter(item).Count() == 1 && matchIndividual == null)
                    {
                        matchIndividual = item;
                    }

                    // check that pricing item meets the specified criteria.
                    if (item.FindAllChildren <LabourFilter>().Cast <LabourFilter>().Where(a => (a.Parameter.ToString().ToUpper() == property.ToString().ToUpper() && a.Value.ToUpper() == value.ToUpper())).Count() > 0)
                    {
                        if (matchCriteria == null)
                        {
                            matchCriteria = item;
                        }
                        else
                        {
                            // multiple price entries were found. using first. value = xxx.
                            if (!WarningsMultipleEntry.Contains(criteria))
                            {
                                WarningsMultipleEntry.Add(criteria);
                                Summary.WriteWarning(this, "Multiple specific pay rate entries were found where [" + property + "]" + (value.ToUpper() != "TRUE" ? " = [" + value + "]." : ".") + "\r\nOnly the first entry will be used. Pay [" + matchCriteria.Value.ToString("#,##0.##") + "].");
                            }
                        }
                    }
                }

                if (matchCriteria == null)
                {
                    // report specific criteria not found in price list
                    string warningString = "No [Pay] rate entry was found 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 pay rate [" + matchIndividual.Value.ToString("#,##0.##") + "] will be used.";
                        price          = matchIndividual.Value;
                    }
                    else
                    {
                        Summary.WriteWarning(this, "\r\nNo alternate pay rate for individuals could be found for the individuals. Add a new [r=LabourPriceGroup] entry in the [r=LabourPricing]");
                    }
                    if (!WarningsNotFound.Contains(criteria))
                    {
                        WarningsNotFound.Add(criteria);
                        Summary.WriteWarning(this, warningString);
                    }
                }
                else
                {
                    price = matchCriteria.Value;
                }
            }
            return(price);
        }
示例#2
0
        /// <summary>
        /// Get value of a specific individual with special requirements check (e.g. breeding sire or draught purchase)
        /// </summary>
        /// <returns>value</returns>
        public double PayRate(LabourType ind, PropertyInfo property, string value)
        {
            double price = 0;

            if (PricingAvailable)
            {
                string criteria = property.Name.ToUpper() + ":" + value.ToUpper();

                //find first pricing entry matching specific criteria
                LabourPriceGroup matchIndividual = null;
                LabourPriceGroup matchCriteria   = null;
                foreach (LabourPriceGroup priceGroup in PayList.FindAllChildren <LabourPriceGroup>())
                {
                    if (priceGroup.Filter(ind) && matchIndividual == null)
                    {
                        matchIndividual = priceGroup;
                    }

                    // check that pricing item meets the specified criteria.
                    var items = priceGroup.FindAllChildren <FilterByProperty>()
                                .Where(f => priceGroup.GetProperty(f.PropertyOfIndividual) == property)
                                .Where(f => f.Value.ToString().ToUpper() == value.ToUpper());

                    var suitableFilters = priceGroup.FindAllChildren <FilterByProperty>()
                                          .Where(a => (priceGroup.GetProperty(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();

                    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.WriteWarning(this, $"Multiple specific pay rate entries were found where [{property}]{(value.ToUpper() != "TRUE" ? " = [" + value + "]." : ".")}\r\nOnly the first entry will be used. Pay [{matchCriteria.Value.ToString("#,##0.##")}].");
                            }
                        }
                    }
                }

                if (matchCriteria == null)
                {
                    // report specific criteria not found in price list
                    string warningString = $"No [Pay] rate entry was found meeting the required criteria [{property.Name}]{(value.ToUpper() != "TRUE" ? " = [" + value + "]." : ".")}";

                    if (matchIndividual != null)
                    {
                        // add using the best pricing available for [][] purchases of xx per head
                        warningString += $"\r\nThe best available pay rate [{matchIndividual.Value:#,##0.##}] will be used.";
                        price          = matchIndividual.Value;
                    }
                    else
                    {
                        Summary.WriteWarning(this, "\r\nNo alternate pay rate for individuals could be found for the individuals. Add a new [r=LabourPriceGroup] entry in the [r=LabourPricing]");
                    }

                    if (!warningsNotFound.Contains(criteria))
                    {
                        warningsNotFound.Add(criteria);
                        Summary.WriteWarning(this, warningString);
                    }
                }
                else
                {
                    price = matchCriteria.Value;
                }
            }
            return(price);
        }