Consignment.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. [UserTracking(typeof(Delivery))]
  29. public class Consignment : Entity, IRemotable, IPersistent, ITaxable, ILicense<LogisticsLicense>
  30. {
  31. [TextBoxEditor]
  32. [EditorSequence(1)]
  33. public string Number { get; set; }
  34. [RequiredColumn]
  35. [Caption("Carrier")]
  36. [EditorSequence(2)]
  37. public SupplierLink Supplier { get; set; }
  38. [MemoEditor]
  39. [EditorSequence(3)]
  40. public string Description { get; set; }
  41. [EditorSequence(4)]
  42. public ConsignmentTypeLink Type { get; set; }
  43. [EditorSequence(5)]
  44. public PurchaseOrderCategoryLink Category { get; set; }
  45. [TimestampEditor]
  46. [EditorSequence(6)]
  47. public DateTime Closed { get; set; }
  48. [TextBoxEditor]
  49. [EditorSequence("Shipping",1)]
  50. public string Origin { get; set; }
  51. [EditorSequence("Shipping",2)]
  52. public PDFDocumentLink BillOfLading { get; set; }
  53. [DateEditor]
  54. [Caption("Est. Shipping Date")]
  55. [EditorSequence("Shipping",3)]
  56. public DateTime EstimatedDispatchDate { get; set; }
  57. [DateEditor]
  58. [Caption("Act. Shipping Date")]
  59. [EditorSequence("Shipping",4)]
  60. public DateTime ActualDispatchDate { get; set; }
  61. [DateEditor]
  62. [Caption("Est. Port Arrival")]
  63. [EditorSequence("Shipping",5)]
  64. public DateTime EstimatedPortArrival { get; set; }
  65. [DateEditor]
  66. [Caption("Act. Port Arrival")]
  67. [EditorSequence("Shipping",6)]
  68. public DateTime ActualPortArrival { get; set; }
  69. [NullEditor]
  70. [EditorSequence("Shipping",7)]
  71. public DateTime EstimatedDepotArrival { get; set; }
  72. [NullEditor]
  73. [EditorSequence("Shipping",8)]
  74. public DateTime ActualDepotArrival { get; set; }
  75. [DateEditor]
  76. [Caption("Est. Warehouse Arrival")]
  77. [EditorSequence("Shipping",9)]
  78. public DateTime EstimatedWarehouseArrival { get; set; }
  79. [DateEditor]
  80. [Caption("Act. Warehouse Arrival")]
  81. [EditorSequence("Shipping",10)]
  82. public DateTime ActualWarehouseArrival { get; set; }
  83. [CurrencyEditor]
  84. [EditorSequence("Costing",1)]
  85. public double ForeignCurrencyCost { get; set; }
  86. [CurrencyEditor(Visible = Visible.Default, Summary = Summary.Sum)]
  87. [EditorSequence("Costing",2)]
  88. public double ExTax { get; set; }
  89. [RequiredColumn]
  90. [EditorSequence("Costing",3)]
  91. public TaxCodeLink TaxCode { get; set; }
  92. [EditorSequence("Costing",4)]
  93. [DoubleEditor(Visible = Visible.Default, Editable = Editable.Hidden)]
  94. public double TaxRate { get; set; }
  95. [EditorSequence("Costing",5)]
  96. [CurrencyEditor(Visible = Visible.Default, Summary = Summary.Sum)]
  97. public double Tax { get; set; }
  98. [EditorSequence("Costing",6)]
  99. [CurrencyEditor(Visible = Visible.Default, Summary = Summary.Sum)]
  100. public double IncTax { get; set; }
  101. [TimestampEditor(Editable = Editable.Hidden)]
  102. [Aggregate(typeof(ConsignmentLastReceived))]
  103. public DateTime LastReceived { get; set; }
  104. [IntegerEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
  105. [Aggregate(typeof(ConsignmentUnreceivedItems))]
  106. public int UnreceivedItems { get; set; }
  107. [Editable(Editable.Disabled)]
  108. [EntityRelationship(DeleteAction.SetNull)]
  109. public BillLineLink BillLine { get; set; }
  110. [NullEditor]
  111. [EntityRelationship(DeleteAction.SetNull)]
  112. public EmployeeLink Employee { get; set; }
  113. [NullEditor]
  114. [Obsolete("Not In Use anymore?", true)]
  115. public string Status { get; set; }
  116. static Consignment()
  117. {
  118. LinkedProperties.Register<Consignment, TaxCodeLink, double>(x => x.TaxCode, x => x.Rate, x => x.TaxRate);
  119. }
  120. private bool bChanging;
  121. protected override void DoPropertyChanged(string name, object? before, object? after)
  122. {
  123. if (bChanging)
  124. return;
  125. try
  126. {
  127. bChanging = true;
  128. if (name.Equals(nameof(ForeignCurrencyCost)) && (after is double foreigncost) &&
  129. Supplier.Currency.ID != Guid.Empty)
  130. {
  131. ExTax = foreigncost / (Supplier.Currency.ExchangeRate.IsEffectivelyEqual(0.0) ? 1.0 : Supplier.Currency.ExchangeRate);
  132. Tax = ExTax * TaxCode.Rate / 100.0;
  133. IncTax = ExTax + Tax;
  134. }
  135. else if (name.Equals(nameof(ExTax)) && after is double extax)
  136. {
  137. ForeignCurrencyCost = extax * (Supplier.Currency.ExchangeRate.IsEffectivelyEqual(0.0) ? 1.0 : Supplier.Currency.ExchangeRate);
  138. Tax = extax * TaxCode.Rate / 100.0;
  139. IncTax = extax + Tax;
  140. }
  141. else if (name.Equals(nameof(TaxRate)) && after is double taxrate)
  142. {
  143. Tax = ExTax * taxrate / 100.0;
  144. IncTax = ExTax + Tax;
  145. }
  146. else if (name.Equals(nameof(Tax)) && after is double tax)
  147. {
  148. IncTax = ExTax + tax;
  149. }
  150. else if (name.Equals(nameof(IncTax)) && after is double inctax)
  151. {
  152. Tax = inctax / (100.0 + TaxCode.Rate) / 100.0;
  153. ExTax = inctax - Tax;
  154. ForeignCurrencyCost = ExTax * (Supplier.Currency.ExchangeRate.IsEffectivelyEqual(0.0) ? 1.0 : Supplier.Currency.ExchangeRate);
  155. }
  156. }
  157. finally
  158. {
  159. bChanging = false;
  160. }
  161. base.DoPropertyChanged(name, before, after);
  162. }
  163. }
  164. }