123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- using System;
- using System.Collections.Generic;
- using System.Linq.Expressions;
- using InABox.Core;
- namespace Comal.Classes
- {
- public class ConsignmentLastReceived : CoreAggregate<Consignment, PurchaseOrderItem, DateTime>
- {
- public override Expression<Func<PurchaseOrderItem, DateTime>> Aggregate => x => x.ReceivedDate;
- public override AggregateCalculation Calculation => AggregateCalculation.Maximum;
- public override Dictionary<Expression<Func<PurchaseOrderItem, object>>, Expression<Func<Consignment, object>>> Links =>
- new Dictionary<Expression<Func<PurchaseOrderItem, object>>, Expression<Func<Consignment, object>>>()
- {
- { PurchaseOrderItem => PurchaseOrderItem.Consignment.ID, Consignment => Consignment.ID }
- };
- }
- public class ConsignmentUnreceivedItems : CoreAggregate<Consignment, PurchaseOrderItem, Guid>
- {
- public override Expression<Func<PurchaseOrderItem, Guid>> Aggregate => x => x.ID;
- public override AggregateCalculation Calculation => AggregateCalculation.Count;
- public override Filter<PurchaseOrderItem> Filter => new Filter<PurchaseOrderItem>(x => x.ReceivedDate).IsEqualTo(DateTime.MinValue);
- public override Dictionary<Expression<Func<PurchaseOrderItem, object>>, Expression<Func<Consignment, object>>> Links =>
- new Dictionary<Expression<Func<PurchaseOrderItem, object>>, Expression<Func<Consignment, object>>>()
- {
- { PurchaseOrderItem => PurchaseOrderItem.Consignment.ID, Consignment => Consignment.ID }
- };
- }
-
- [UserTracking(typeof(Delivery))]
- public class Consignment : Entity, IRemotable, IPersistent, ITaxable, ILicense<LogisticsLicense>
- {
- [TextBoxEditor]
- [EditorSequence(1)]
- public string Number { get; set; }
-
- [RequiredColumn]
- [Caption("Carrier")]
- [EditorSequence(2)]
- public SupplierLink Supplier { get; set; }
-
- [MemoEditor]
- [EditorSequence(3)]
- public string Description { get; set; }
-
- [EditorSequence(4)]
- public ConsignmentTypeLink Type { get; set; }
- [EditorSequence(5)]
- public PurchaseOrderCategoryLink Category { get; set; }
-
- [TimestampEditor]
- [EditorSequence(6)]
- public DateTime Closed { get; set; }
-
- [TextBoxEditor]
- [EditorSequence("Shipping",1)]
- public string Origin { get; set; }
-
- [EditorSequence("Shipping",2)]
- public PDFDocumentLink BillOfLading { get; set; }
-
- [DateEditor]
- [Caption("Est. Shipping Date")]
- [EditorSequence("Shipping",3)]
- public DateTime EstimatedDispatchDate { get; set; }
- [DateEditor]
- [Caption("Act. Shipping Date")]
- [EditorSequence("Shipping",4)]
- public DateTime ActualDispatchDate { get; set; }
- [DateEditor]
- [Caption("Est. Port Arrival")]
- [EditorSequence("Shipping",5)]
- public DateTime EstimatedPortArrival { get; set; }
- [DateEditor]
- [Caption("Act. Port Arrival")]
- [EditorSequence("Shipping",6)]
- public DateTime ActualPortArrival { get; set; }
- [NullEditor]
- [EditorSequence("Shipping",7)]
- public DateTime EstimatedDepotArrival { get; set; }
- [NullEditor]
- [EditorSequence("Shipping",8)]
- public DateTime ActualDepotArrival { get; set; }
- [DateEditor]
- [Caption("Est. Warehouse Arrival")]
- [EditorSequence("Shipping",9)]
- public DateTime EstimatedWarehouseArrival { get; set; }
- [DateEditor]
- [Caption("Act. Warehouse Arrival")]
- [EditorSequence("Shipping",10)]
- public DateTime ActualWarehouseArrival { get; set; }
-
- [CurrencyEditor]
- [EditorSequence("Costing",1)]
- public double ForeignCurrencyCost { get; set; }
-
- [CurrencyEditor(Visible = Visible.Default, Summary = Summary.Sum)]
- [EditorSequence("Costing",2)]
- public double ExTax { get; set; }
-
- [RequiredColumn]
- [EditorSequence("Costing",3)]
- public TaxCodeLink TaxCode { get; set; }
-
- [EditorSequence("Costing",4)]
- [DoubleEditor(Visible = Visible.Default, Editable = Editable.Hidden)]
- public double TaxRate { get; set; }
- [EditorSequence("Costing",5)]
- [CurrencyEditor(Visible = Visible.Default, Summary = Summary.Sum)]
- public double Tax { get; set; }
- [EditorSequence("Costing",6)]
- [CurrencyEditor(Visible = Visible.Default, Summary = Summary.Sum)]
- public double IncTax { get; set; }
-
- [TimestampEditor(Editable = Editable.Hidden)]
- [Aggregate(typeof(ConsignmentLastReceived))]
- public DateTime LastReceived { get; set; }
- [IntegerEditor(Visible = Visible.Optional, Editable = Editable.Hidden)]
- [Aggregate(typeof(ConsignmentUnreceivedItems))]
- public int UnreceivedItems { get; set; }
- [Editable(Editable.Disabled)]
- [EntityRelationship(DeleteAction.SetNull)]
- public BillLineLink BillLine { get; set; }
-
- [NullEditor]
- [EntityRelationship(DeleteAction.SetNull)]
- public EmployeeLink Employee { get; set; }
-
- [NullEditor]
- [Obsolete("Not In Use anymore?", true)]
- public string Status { get; set; }
- static Consignment()
- {
- LinkedProperties.Register<Consignment, TaxCodeLink, double>(x => x.TaxCode, x => x.Rate, x => x.TaxRate);
- }
-
- private bool bChanging;
- protected override void DoPropertyChanged(string name, object? before, object? after)
- {
- if (bChanging)
- return;
- try
- {
- bChanging = true;
-
- if (name.Equals(nameof(ForeignCurrencyCost)) && (after is double foreigncost) &&
- Supplier.Currency.ID != Guid.Empty)
- {
- ExTax = foreigncost / (Supplier.Currency.ExchangeRate.IsEffectivelyEqual(0.0) ? 1.0 : Supplier.Currency.ExchangeRate);
- Tax = ExTax * TaxCode.Rate / 100.0;
- IncTax = ExTax + Tax;
- }
- else if (name.Equals(nameof(ExTax)) && after is double extax)
- {
- ForeignCurrencyCost = extax * (Supplier.Currency.ExchangeRate.IsEffectivelyEqual(0.0) ? 1.0 : Supplier.Currency.ExchangeRate);
- Tax = extax * TaxCode.Rate / 100.0;
- IncTax = extax + Tax;
- }
-
- else if (name.Equals(nameof(TaxRate)) && after is double taxrate)
- {
- Tax = ExTax * taxrate / 100.0;
- IncTax = ExTax + Tax;
- }
-
- else if (name.Equals(nameof(Tax)) && after is double tax)
- {
- IncTax = ExTax + tax;
- }
- else if (name.Equals(nameof(IncTax)) && after is double inctax)
- {
- Tax = inctax / (100.0 + TaxCode.Rate) / 100.0;
- ExTax = inctax - Tax;
- ForeignCurrencyCost = ExTax * (Supplier.Currency.ExchangeRate.IsEffectivelyEqual(0.0) ? 1.0 : Supplier.Currency.ExchangeRate);
- }
-
- }
- finally
- {
- bChanging = false;
- }
- base.DoPropertyChanged(name, before, after);
- }
- }
- }
|