| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.ComponentModel;
 
- using System.Linq;
 
- using System.Linq.Expressions;
 
- using InABox.Clients;
 
- using InABox.Core;
 
- namespace Comal.Classes
 
- {
 
-     public class DeliveryDocumentCount : CoreAggregate<Delivery, DeliveryDocument, Guid>
 
-     {
 
-         public override Expression<Func<DeliveryDocument, Guid>> Aggregate => x => x.ID;
 
-         public override AggregateCalculation Calculation => AggregateCalculation.Count;
 
-         public override Dictionary<Expression<Func<DeliveryDocument, object>>, Expression<Func<Delivery, object>>> Links =>
 
-             new Dictionary<Expression<Func<DeliveryDocument, object>>, Expression<Func<Delivery, object>>>()
 
-             {
 
-                 { DeliveryDocument => DeliveryDocument.EntityLink.ID, Delivery => Delivery.ID }
 
-             };
 
-     }
 
-     [UserTracking("Logistics")]
 
-     [Caption("Deliveries")]
 
-     public class Delivery : Entity, IPersistent, IRemotable, INumericAutoIncrement<Delivery>, IOneToMany<Assignment>, ILicense<LogisticsLicense>,
 
-         IExportable, IImportable
 
-     {
 
-         [EditorSequence(1)]
 
-         [IntegerEditor]
 
-         public int Number { get; set; }
 
-         [EditorSequence(2)]
 
-         public DeliveryTypeLink Type { get; set; }
 
-         [EditorSequence(3)]
 
-         public JobLink Job { get; set; }
 
-         [EditorSequence(4)]
 
-         public ContactLink Contact { get; set; }
 
-         [EditorSequence(5)]
 
-         public Address Address { get; set; }
 
-         [EditorSequence(6)]
 
-         [MemoEditor]
 
-         public string Notes { get; set; }
 
-         [EntityRelationship(DeleteAction.SetNull)]
 
-         [EditorSequence(7)]
 
-         public AssignmentLink Assignment { get; set; }
 
-         [EditorSequence(8)]
 
-         public EmployeeLink Employee { get; set; }
 
-         [DateTimeEditor]
 
-         [EditorSequence(9)]
 
-         public DateTime Due { get; set; }
 
-         [Aggregate(typeof(DeliveryDocumentCount))]
 
-         [IntegerEditor(Editable = Editable.Hidden)]
 
-         public int Documents { get; set; }
 
-         [TimestampEditor]
 
-         [EditorSequence(10)]
 
-         public DateTime Delivered { get; set; }
 
-         [EditorSequence(11)]
 
-         public EmployeeLink DeliveredBy { get; set; }
 
-         [NullEditor]
 
-         public Location Location { get; set; }
 
-         [TimestampEditor(Editable = Editable.Disabled)]
 
-         [EditorSequence(12)]
 
-         public DateTime Completed { get; set; }
 
-         [NullEditor]
 
-         public int KanbanNumber { get; set; }
 
-         public Expression<Func<Delivery, int>> AutoIncrementField()
 
-         {
 
-             return x => x.Number;
 
-         }
 
-         public Filter<Delivery> AutoIncrementFilter()
 
-         {
 
-             return null;
 
-         }
 
-         //this only refers to a kanban generated by the deliveries mobile app - not a kanban which may have generated the delivery
 
-         protected override void Init()
 
-         {
 
-             base.Init();
 
-             Employee = new EmployeeLink();
 
-             Assignment = new AssignmentLink();
 
-             Job = new JobLink();
 
-             Job.PropertyChanged += Job_PropertyChanged;
 
-             Contact = new ContactLink();
 
-             Contact.PropertyChanged += Contact_PropertyChanged;
 
-             Address = new Address();
 
-             Location = new Location();
 
-             Type = new DeliveryTypeLink();
 
-             DeliveredBy = new EmployeeLink();
 
-             KanbanNumber = 0;
 
-         }
 
-         private void Contact_PropertyChanged(object sender, PropertyChangedEventArgs e)
 
-         {
 
-             if (string.Equals(e.PropertyName, "ID"))
 
-             {
 
-                 var contactLink = (sender as ContactLink)!;
 
-                 CoreTable results = null;
 
-                 if (contactLink.IsValid())
 
-                     results = new Client<Contact>().Query(
 
-                         new Filter<Contact>(x => x.ID).IsEqualTo(contactLink.ID),
 
-                         new Columns<Contact>(
 
-                             x => x.Address.Street,
 
-                             x => x.Address.City,
 
-                             x => x.Address.State,
 
-                             x => x.Address.PostCode
 
-                         )
 
-                     );
 
-                 var row = results?.Rows.FirstOrDefault();
 
-                 Address.Street = row != null ? row.Get<Contact, string>(x => x.Address.Street) : "";
 
-                 Address.City = row != null ? row.Get<Contact, string>(x => x.Address.City) : "";
 
-                 Address.State = row != null ? row.Get<Contact, string>(x => x.Address.State) : "";
 
-                 Address.PostCode = row != null ? row.Get<Contact, string>(x => x.Address.PostCode) : "";
 
-             }
 
-         }
 
-         private void Job_PropertyChanged(object sender, PropertyChangedEventArgs e)
 
-         {
 
-             //if (string.Equals(e.PropertyName, "ID") && !Contact.IsValid())
 
-             //{
 
-             //    var jobLink = sender as JobLink;
 
-             //    CoreTable results = null;
 
-             //    if (jobLink.IsValid())
 
-             //        results = new Client<Job>().Query(
 
-             //            new Filter<Job>(x => x.ID).IsEqualTo(jobLink.ID),
 
-             //            new Columns<Job>(
 
-             //                x => x.SiteAddress.Street,
 
-             //                x => x.SiteAddress.City,
 
-             //                x => x.SiteAddress.State,
 
-             //                x => x.SiteAddress.PostCode
 
-             //            )
 
-             //        );
 
-             //    var row = results?.Rows.FirstOrDefault();
 
-             //    Address.Street = row != null ? row.Get<Job, string>(x => x.SiteAddress.Street) : "";
 
-             //    Address.City = row != null ? row.Get<Job, string>(x => x.SiteAddress.City) : "";
 
-             //    Address.State = row != null ? row.Get<Job, string>(x => x.SiteAddress.State) : "";
 
-             //    Address.PostCode = row != null ? row.Get<Job, string>(x => x.SiteAddress.PostCode) : "";
 
-             //}
 
-         }
 
-         #region Move to Assignments?
 
-         [NullEditor]
 
-         public DateTime Date { get; set; }
 
-         [NullEditor]
 
-         public TimeSpan Start { get; set; }
 
-         [NullEditor]
 
-         public TimeSpan Finish { get; set; }
 
-         private bool bChanging;
 
-         protected override void DoPropertyChanged(string name, object before, object after)
 
-         {
 
-             base.DoPropertyChanged(name, before, after);
 
-             if (bChanging)
 
-                 return;
 
-             bChanging = true;
 
-             if (name.Equals("Start"))
 
-                 Finish = ((TimeSpan)after).Add(Duration);
 
-             else if (name.Equals("Finish"))
 
-                 Duration = ((TimeSpan)after).Subtract(Start);
 
-             else if (name.Equals("Duration")) Finish = Start.Add((TimeSpan)after);
 
-             bChanging = false;
 
-         }
 
-         [NullEditor]
 
-         public TimeSpan Duration { get; set; }
 
-         #endregion
 
-     }
 
- }
 
 
  |