PurchaseOrderItemAllocation.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using InABox.Core;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace Comal.Classes
  7. {
  8. [Caption("Allocation")]
  9. public class PurchaseOrderItemAllocation : Entity, IRemotable, IPersistent, ILicense<ProjectManagementLicense>
  10. , IOneToMany<JobRequisitionItem>, IOneToMany<Job>, IOneToMany<PurchaseOrderItem>
  11. {
  12. [EntityRelationship(DeleteAction.Cascade)]
  13. public PurchaseOrderItemLink Item { get; set; }
  14. /// <summary>
  15. /// This may not be blank.
  16. /// </summary>
  17. [EntityRelationship(DeleteAction.Cascade)]
  18. [EditorSequence(1)]
  19. public JobLink Job { get; set; }
  20. private class JobRequisitionItemLookup : LookupDefinitionGenerator<JobRequisitionItem, PurchaseOrderItemAllocation>
  21. {
  22. public override Columns<PurchaseOrderItemAllocation> DefineFilterColumns()
  23. {
  24. return base.DefineFilterColumns().Add(x => x.Job.ID);
  25. }
  26. public override Filter<JobRequisitionItem>? DefineFilter(PurchaseOrderItemAllocation[] items)
  27. {
  28. return new Filter<JobRequisitionItem>(x => x.Job.ID).InList(items.ToArray(x => x.Job.ID));
  29. }
  30. }
  31. /// <summary>
  32. /// This may be an empty link. The interface is as such: if there is no JRI, then we are creating a reserve and allocation just against the job. If there is a JRI,
  33. /// then received stock is reserved and allocated for the JRI.
  34. /// </summary>
  35. [EntityRelationship(DeleteAction.Cascade)]
  36. [LookupDefinition(typeof(JobRequisitionItemLookup))]
  37. [EditorSequence(2)]
  38. public JobRequisitionItemLink JobRequisitionItem { get; set; }
  39. [EditorSequence(3)]
  40. public double Quantity { get; set; }
  41. [NullEditor]
  42. public bool Nominated { get; set; }
  43. protected override void DoPropertyChanged(string name, object? before, object? after)
  44. {
  45. base.DoPropertyChanged(name, before, after);
  46. if(name == $"{nameof(Job)}.{nameof(Job.ID)}")
  47. {
  48. JobRequisitionItem.ID = Guid.Empty;
  49. JobRequisitionItem.Clear();
  50. }
  51. }
  52. }
  53. public class PurchaseOrderItemAllocationJobLink : EntityLink<PurchaseOrderItemAllocation>
  54. {
  55. [NullEditor]
  56. public override Guid ID { get; set; }
  57. public LightJobLink Job { get; set; }
  58. public LightPurchaseOrderItemLink Item { get; set; }
  59. }
  60. }