diff --git a/docs/8.0/ayanova/docs/svc-contracts.md b/docs/8.0/ayanova/docs/svc-contracts.md index d4cf313d..28f065a0 100644 --- a/docs/8.0/ayanova/docs/svc-contracts.md +++ b/docs/8.0/ayanova/docs/svc-contracts.md @@ -11,4 +11,7 @@ NOTES FOR DOC - TAGS: tagged override items are matched to objects when the object has **ALL** the tags specified in the Contract override. If a Contract has a Labor price override when tagged with "red, green" then the work order item Labor record *must* have both the "red" and "green" tags amongst it's tags to match. E.G. a Contract part override for Travel rates tagged with "zone-5, van" would match with a Travel rate tagged with "zone-5,zone-6,zone-7,van" (both tags present) but would not match with a Travel rate tagged with "zone-5, car" (only one tag present). - PRECEDENCE: Tagged Contract price overrides take precedence over general Contract price overrides. For example, if a Contract has a general discount for Labor rates and also has a tag override for a Labor record and the tags match then the tag override is the one used and the general override is ignored. If no tags matched then the general price override would be applied. -If there is more than one tagged Contract price override that could match, the first one that matches is used so it is important to ensure that the tags are selected as specifically as possible with this in mind. \ No newline at end of file + +Conflict - multiple potential matches: +Contract tagged items are checked against the object in order of the contract tagged override with the most tags to the contract override with the least tags. This is done to try to make the most specific possible tag match. For example, a contract with 3 tagged labor price overrides and their tags selected are: "green", "red, green, blue", "orange, green". AyaNova will attempt to match by starting with the contract labor override with the most tags: "red,green,blue" then "orange,green" and finally "green". If a record is saved tagged with "orange,red,yellow,green,black,blue" it will be matched to the first item tagged "red,green,blue" as it has the most terms that match and it's override terms will be used and the other two will not be used. + diff --git a/server/AyaNova/biz/WorkOrderBiz.cs b/server/AyaNova/biz/WorkOrderBiz.cs index 05d73ae0..38881689 100644 --- a/server/AyaNova/biz/WorkOrderBiz.cs +++ b/server/AyaNova/biz/WorkOrderBiz.cs @@ -1895,15 +1895,20 @@ namespace AyaNova.Biz } //CONTRACT ADJUSTMENTS - + //First check if there is a matching tagged service rate contract discount, that takes precedence - if(c.ContractServiceRateOverrideItems.Count>0){ + if (c.ContractServiceRateOverrideItems.Count > 0) + { //does our contract rate have a matching tag? - - //TODO: Iterate all contract tagged items, use the one with the MOST matching tags - foreach(var csr in c.ContractServiceRateOverrideItems){ - csr.Tags.All(z => Rate.Tags.Any(x => x == z)); - } + + //Iterate all contract tagged items in order of ones with the most tags first + foreach (var csr in c.ContractServiceRateOverrideItems.OrderByDescending(z => z.Tags.Count)) + if (csr.Tags.All(z => Rate.Tags.Any(x => x == z))) + { + + break; + } + }