LaborRuleBase.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ProjectEntryLaborAdjust
  4. {
  5. public abstract class LaborRuleBase
  6. {
  7. public string InventoryCD { get; }
  8. public string Description { get; protected set; }
  9. public HashSet<string> ExcludedBranchCDs { get; }
  10. public HashSet<string> ExcludedTemplateCDs { get; }
  11. public HashSet<string> ExcludedBillRules { get; }
  12. /// <summary>
  13. /// Optional project creation cutoff date. If set, any project whose CreatedDateTime
  14. /// is strictly before this date will be excluded (rule will be skipped).
  15. /// Date part is compared (time-of-day ignored).
  16. /// </summary>
  17. public DateTime? ProjectDate { get; set; }
  18. /// <summary>
  19. /// Optional fixed unit rate. If null, the AR pricing engine (defaults) should apply.
  20. /// </summary>
  21. public virtual decimal? FixedUnitRate
  22. {
  23. get { return null; }
  24. }
  25. protected LaborRuleBase(string inventoryCD, string description = null)
  26. {
  27. if (string.IsNullOrWhiteSpace(inventoryCD))
  28. throw new ArgumentException("inventoryCD");
  29. InventoryCD = inventoryCD.Trim();
  30. Description = string.IsNullOrWhiteSpace(description)
  31. ? "Auto-added Labor (" + InventoryCD + ")"
  32. : description.Trim();
  33. ExcludedBranchCDs = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
  34. ExcludedTemplateCDs = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
  35. ExcludedBillRules = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
  36. }
  37. /// <summary>Compute the quantity (hours) for this labor item from the job size.</summary>
  38. public abstract decimal GetHours(decimal jobSize, DateTime? projectCreatedDate);
  39. /// <summary>Check if this rule should be skipped under the provided context.</summary>
  40. public virtual bool IsExcludedFor(string branchCD, string templateCD, string billRule, DateTime? projectCreatedDate)
  41. {
  42. if (!string.IsNullOrWhiteSpace(branchCD) && ExcludedBranchCDs.Contains(branchCD.Trim())) return true;
  43. if (!string.IsNullOrWhiteSpace(templateCD) && ExcludedTemplateCDs.Contains(templateCD.Trim())) return true;
  44. if (!string.IsNullOrWhiteSpace(billRule) && ExcludedBillRules.Contains(billRule.Trim())) return true;
  45. return false;
  46. }
  47. }
  48. }