Consignment.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using InABox.Core;
  5. namespace Comal.Classes
  6. {
  7. public class ConsignmentLastReceived : CoreAggregate<Consignment, PurchaseOrderItem, DateTime>
  8. {
  9. public override Expression<Func<PurchaseOrderItem, DateTime>> Aggregate => x => x.ReceivedDate;
  10. public override AggregateCalculation Calculation => AggregateCalculation.Maximum;
  11. public override Dictionary<Expression<Func<PurchaseOrderItem, object>>, Expression<Func<Consignment, object>>> Links =>
  12. new Dictionary<Expression<Func<PurchaseOrderItem, object>>, Expression<Func<Consignment, object>>>()
  13. {
  14. { PurchaseOrderItem => PurchaseOrderItem.Consignment.ID, Consignment => Consignment.ID }
  15. };
  16. }
  17. public class ConsignmentUnreceivedItems : CoreAggregate<Consignment, PurchaseOrderItem, Guid>
  18. {
  19. public override Expression<Func<PurchaseOrderItem, Guid>> Aggregate => x => x.ID;
  20. public override AggregateCalculation Calculation => AggregateCalculation.Count;
  21. public override Filter<PurchaseOrderItem> Filter => new Filter<PurchaseOrderItem>(x => x.ReceivedDate).IsEqualTo(DateTime.MinValue);
  22. public override Dictionary<Expression<Func<PurchaseOrderItem, object>>, Expression<Func<Consignment, object>>> Links =>
  23. new Dictionary<Expression<Func<PurchaseOrderItem, object>>, Expression<Func<Consignment, object>>>()
  24. {
  25. { PurchaseOrderItem => PurchaseOrderItem.Consignment.ID, Consignment => Consignment.ID }
  26. };
  27. }
  28. //public class ConsignmentClosed : ICondition<Consignment, int, DateTime>
  29. //{
  30. // public static readonly DateTime DefaultDate = DateTime.MinValue;
  31. // public Expression<Func<Consignment, int>> Left => x => x.UnreceivedItems;
  32. // public Condition Condition => Condition.Equals;
  33. // public Expression<Func<Consignment, int>> Right => x => 0;
  34. // public Expression<Func<Consignment, DateTime>> True => x => x.LastReceived;
  35. // public Expression<Func<Consignment, DateTime>> False => x => DateTime.MinValue;
  36. //}
  37. [UserTracking(typeof(Delivery))]
  38. public class Consignment : Entity, IRemotable, IPersistent, ITaxable, ILicense<LogisticsLicense>
  39. {
  40. [TextBoxEditor]
  41. [EditorSequence(0)]
  42. public string Number { get; set; }
  43. [EditorSequence(1)]
  44. public ConsignmentTypeLink Type { get; set; }
  45. [EditorSequence(2)]
  46. public PurchaseOrderCategoryLink Category { get; set; }
  47. [Caption("Carrier")]
  48. [EditorSequence(3)]
  49. public SupplierLink Supplier { get; set; }
  50. [TextBoxEditor]
  51. [EditorSequence(4)]
  52. public string Origin { get; set; }
  53. [TextBoxEditor]
  54. [EditorSequence(5)]
  55. public string Description { get; set; }
  56. [DateEditor]
  57. [Caption("Est. Shipping Date")]
  58. [EditorSequence(6)]
  59. public DateTime EstimatedDispatchDate { get; set; }
  60. [DateEditor]
  61. [Caption("Act. Shipping Date")]
  62. [EditorSequence(7)]
  63. public DateTime ActualDispatchDate { get; set; }
  64. [DateEditor]
  65. [Caption("Est. Port Arrival")]
  66. [EditorSequence(8)]
  67. public DateTime EstimatedPortArrival { get; set; }
  68. [DateEditor]
  69. [Caption("Act. Port Arrival")]
  70. [EditorSequence(9)]
  71. public DateTime ActualPortArrival { get; set; }
  72. [NullEditor]
  73. [EditorSequence(10)]
  74. public DateTime EstimatedDepotArrival { get; set; }
  75. [NullEditor]
  76. [EditorSequence(11)]
  77. public DateTime ActualDepotArrival { get; set; }
  78. [DateEditor]
  79. [Caption("Est. Warehouse Arrival")]
  80. [EditorSequence(12)]
  81. public DateTime EstimatedWarehouseArrival { get; set; }
  82. [DateEditor]
  83. [Caption("Act. Warehouse Arrival")]
  84. [EditorSequence(13)]
  85. public DateTime ActualWarehouseArrival { get; set; }
  86. [TextBoxEditor]
  87. [EditorSequence(14)]
  88. public string Status { get; set; }
  89. [EditorSequence(14)]
  90. public PDFDocumentLink BillOfLading { get; set; }
  91. [TimestampEditor(Editable = Editable.Disabled)]
  92. [EditorSequence(15)]
  93. [Aggregate(typeof(ConsignmentLastReceived))]
  94. public DateTime LastReceived { get; set; }
  95. [IntegerEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
  96. [Aggregate(typeof(ConsignmentUnreceivedItems))]
  97. public int UnreceivedItems { get; set; }
  98. [TimestampEditor] //(Editable = Editable.Disabled)]
  99. [EditorSequence(16)]
  100. //[Condition(typeof(ConsignmentClosed))]
  101. public DateTime Closed { get; set; }
  102. [NullEditor]
  103. [EditorSequence(17)]
  104. public EmployeeLink Employee { get; set; }
  105. [CurrencyEditor(Visible = Visible.Default, Summary = Summary.Sum)]
  106. [EditorSequence(18)]
  107. public double ExTax { get; set; }
  108. [RequiredColumn]
  109. [EditorSequence(19)]
  110. public TaxCodeLink TaxCode { get; set; }
  111. [EditorSequence(20)]
  112. [DoubleEditor(Visible = Visible.Default, Editable = Editable.Hidden)]
  113. public double TaxRate { get; set; }
  114. [EditorSequence(21)]
  115. [CurrencyEditor(Visible = Visible.Default, Summary = Summary.Sum)]
  116. public double Tax { get; set; }
  117. [EditorSequence(22)]
  118. [CurrencyEditor(Visible = Visible.Default, Summary = Summary.Sum)]
  119. public double IncTax { get; set; }
  120. [NullEditor]
  121. [EntityRelationship(DeleteAction.SetNull)]
  122. public BillLineLink BillLine { get; set; }
  123. static Consignment()
  124. {
  125. LinkedProperties.Register<Consignment, TaxCodeLink, double>(x => x.TaxCode, x => x.Rate, x => x.TaxRate);
  126. }
  127. private bool bChanging;
  128. protected override void DoPropertyChanged(string name, object? before, object? after)
  129. {
  130. if (bChanging)
  131. return;
  132. try
  133. {
  134. bChanging = true;
  135. if (name.Equals(nameof(ExTax)) && after is double extax)
  136. {
  137. Tax = extax * TaxCode.Rate / 100.0;
  138. IncTax = extax + Tax;
  139. }
  140. else if (name.Equals(nameof(TaxRate)) && after is double taxrate)
  141. {
  142. Tax = ExTax * taxrate / 100.0;
  143. IncTax = ExTax + Tax;
  144. }
  145. else if (name.Equals(nameof(Tax)) && after is double tax)
  146. {
  147. IncTax = ExTax + tax;
  148. }
  149. else if (name.Equals(nameof(IncTax)) && after is double inctax)
  150. {
  151. Tax = inctax / (100.0 + TaxCode.Rate) / 100.0;
  152. ExTax = inctax - Tax;
  153. }
  154. }
  155. finally
  156. {
  157. bChanging = false;
  158. }
  159. base.DoPropertyChanged(name, before, after);
  160. }
  161. }
  162. }