using System; using System.Collections.Generic; namespace ProjectEntryLaborAdjust { public abstract class LaborRuleBase { public string InventoryCD { get; } public string Description { get; protected set; } public HashSet ExcludedBranchCDs { get; } public HashSet ExcludedTemplateCDs { get; } public HashSet ExcludedBillRules { get; } /// /// Optional project creation cutoff date. If set, any project whose CreatedDateTime /// is strictly before this date will be excluded (rule will be skipped). /// Date part is compared (time-of-day ignored). /// public DateTime? ProjectDate { get; set; } /// /// Optional fixed unit rate. If null, the AR pricing engine (defaults) should apply. /// public virtual decimal? FixedUnitRate { get { return null; } } protected LaborRuleBase(string inventoryCD, string description = null) { if (string.IsNullOrWhiteSpace(inventoryCD)) throw new ArgumentException("inventoryCD"); InventoryCD = inventoryCD.Trim(); Description = string.IsNullOrWhiteSpace(description) ? "Auto-added Labor (" + InventoryCD + ")" : description.Trim(); ExcludedBranchCDs = new HashSet(StringComparer.OrdinalIgnoreCase); ExcludedTemplateCDs = new HashSet(StringComparer.OrdinalIgnoreCase); ExcludedBillRules = new HashSet(StringComparer.OrdinalIgnoreCase); } /// Compute the quantity (hours) for this labor item from the job size. public abstract decimal GetHours(decimal jobSize, DateTime? projectCreatedDate); /// Check if this rule should be skipped under the provided context. public virtual bool IsExcludedFor(string branchCD, string templateCD, string billRule, DateTime? projectCreatedDate) { if (!string.IsNullOrWhiteSpace(branchCD) && ExcludedBranchCDs.Contains(branchCD.Trim())) return true; if (!string.IsNullOrWhiteSpace(templateCD) && ExcludedTemplateCDs.Contains(templateCD.Trim())) return true; if (!string.IsNullOrWhiteSpace(billRule) && ExcludedBillRules.Contains(billRule.Trim())) return true; return false; } } }