Browse Source

PRS MOBILE - Assignments module changes using actual / booked time

Nick-PRSDigital@bitbucket.org 2 years ago
parent
commit
1ab41adc5b

+ 3 - 3
prs.mobile/comal.timesheets/Assignments/AssignmentColumn.xaml.cs

@@ -80,11 +80,11 @@ namespace comal.timesheets.iOS.Assignments
                     var assignment = new Assignment()
                     {
                         Date = e.Datetime.Date,
-                        Start = e.Datetime.TimeOfDay,
-                        Finish = e.Datetime.TimeOfDay.Add(new TimeSpan(1, 0, 0)),
-                        Duration = new TimeSpan(1, 0, 0),
                         Title = "New Assignment"
                     };
+                    assignment.Booked.Start = e.Datetime.TimeOfDay;
+                    assignment.Booked.Finish = e.Datetime.TimeOfDay.Add(new TimeSpan(1, 0, 0));
+                    assignment.Booked.Duration = new TimeSpan(1, 0, 0);
                     assignment.EmployeeLink.ID = App.Data.Employee.ID;
                     var editor = new AssignmentEdit(assignment);
                     Navigation.PushAsync(editor);

+ 6 - 9
prs.mobile/comal.timesheets/Assignments/AssignmentList.xaml.cs

@@ -303,17 +303,16 @@ namespace comal.timesheets
         }
 
         private void CreateAssignment(DateTime date, ScheduleResource resource)
-        {
-            
+        {           
             var assignment = new Assignment()
             {
                 Date = date.Date,
-                Start = new TimeSpan(date.TimeOfDay.Hours, 0, 0),
-                Finish = date.TimeOfDay.Add(new TimeSpan(1, 0, 0)),
-                Duration = new TimeSpan(1, 0, 0),
                 Title = "New Assignment",
             };
-            
+            assignment.Booked.Start = new TimeSpan(date.TimeOfDay.Hours, 0, 0);
+            assignment.Booked.Finish = date.TimeOfDay.Add(new TimeSpan(1, 0, 0));
+            assignment.Booked.Duration = new TimeSpan(1, 0, 0);
+
             assignment.EmployeeLink.ID = (resource is ScheduleResource sr)
                 ? (Guid)sr.Id
                 : App.Data.Employee.ID;
@@ -345,9 +344,7 @@ namespace comal.timesheets
             }            
             
             var editor = new AssignmentEdit(assignment);
-            Navigation.PushAsync(editor);
-
-            
+            Navigation.PushAsync(editor);            
         }
         
         private async Task DeleteAssignment(Guid id)

+ 30 - 9
prs.mobile/comal.timesheets/Assignments/DataModels/AssignmentEditDataModel.cs

@@ -71,9 +71,12 @@ namespace comal.timesheets
             .Add(x => x.Title)
             .Add(x => x.Description)
             .Add(x => x.Date)
-            .Add(x => x.Start)
-            .Add(x => x.Duration)
-            .Add(x => x.Finish)
+            .Add(x => x.Actual.Start)
+            .Add(x => x.Actual.Duration)
+            .Add(x => x.Actual.Finish)
+            .Add(x => x.Booked.Start)
+            .Add(x => x.Booked.Duration)
+            .Add(x => x.Booked.Finish)
             .Add(c => c.JobLink.ID)
             .Add(c => c.JobLink.JobNumber)
             .Add(c => c.JobLink.Name)
@@ -190,20 +193,38 @@ namespace comal.timesheets
 
         public TimeSpan Start
         {
-            get => GetValue(c => c.Start);
-            set => UpdateValue(c => c.Start, value);
+            get 
+            {
+                var start = GetValue(c => c.Actual.Start);
+                if (start == TimeSpan.Zero)
+                    start = GetValue(c => c.Booked.Start);
+                return start;
+            }
+            set => UpdateValue(c => c.Actual.Start, value);
         }
 
         public TimeSpan Duration
         {
-            get => GetValue(c => c.Duration);
-            set => UpdateValue(c => c.Duration, value);
+            get
+            {
+                var duration = GetValue(c => c.Actual.Duration);
+                if (duration == TimeSpan.Zero)
+                    duration = GetValue(c => c.Booked.Duration);
+                return duration;
+            }
+            set => UpdateValue(c => c.Actual.Duration, value);
         }
         
         public TimeSpan Finish 
         {
-            get => GetValue(c => c.Finish);
-            set => UpdateValue(c => c.Finish, value);
+            get
+            {
+                var finish = GetValue(c => c.Actual.Finish);
+                if (finish == TimeSpan.Zero)
+                    finish = GetValue(c => c.Booked.Finish);
+                return finish;
+            }
+            set => UpdateValue(c => c.Actual.Finish, value);
         }
         
         public Guid JobID 

+ 52 - 34
prs.mobile/comal.timesheets/Assignments/DataModels/AssignmentListDataModel.cs

@@ -5,6 +5,7 @@ using System.Linq;
 using Comal.Classes;
 using InABox.Core;
 using Xamarin.Forms;
+using static Android.InputMethodServices.Keyboard;
 
 namespace comal.timesheets
 {
@@ -13,57 +14,75 @@ namespace comal.timesheets
     public class AssignmentListDataModel : ListDataModel<Assignment, AssignmentListDataModelItem>
     {
         public override Columns<Assignment> Columns => new Columns<Assignment>(x => x.ID)
-            .Add(x=>x.Number)
-            .Add(x=>x.Title)
-            .Add(x=>x.Description)
-            .Add(x=>x.Date)
-            .Add(x=>x.Start)
-            .Add(x=>x.Finish)
-            .Add(x=>x.ActivityLink.Color)
-            .Add(x=>x.EmployeeLink.ID)
-            .Add(x=>x.JobLink.ID)
-            .Add(x=>x.JobLink.JobNumber)
-            .Add(x=>x.JobLink.Name)
-            .Add(x=>x.Task.ID)
-            .Add(x=>x.Task.Number)
-            .Add(x=>x.Task.Title)
-            .Add(x=>x.Completed);
-        
-        
-        
+            .Add(x => x.Number)
+            .Add(x => x.Title)
+            .Add(x => x.Description)
+            .Add(x => x.Date)
+            .Add(x => x.Actual.Start)
+            .Add(x => x.Actual.Finish)
+            .Add(x => x.Booked.Start)
+            .Add(x => x.Booked.Finish)
+            .Add(x => x.ActivityLink.Color)
+            .Add(x => x.EmployeeLink.ID)
+            .Add(x => x.JobLink.ID)
+            .Add(x => x.JobLink.JobNumber)
+            .Add(x => x.JobLink.Name)
+            .Add(x => x.Task.ID)
+            .Add(x => x.Task.Number)
+            .Add(x => x.Task.Title)
+            .Add(x => x.Completed);
     }
-    
+
     public class AssignmentListDataModelItem : CoreDataModelItem
     {
-        
+
         public Guid Id => Row.Get<Assignment, Guid>(c => c.ID);
 
         public int Number => Row.Get<Assignment, int>(c => c.Number);
-        
+
         public Guid EmployeeId => Row.Get<Assignment, Guid>(c => c.EmployeeLink.ID);
-        
+
         public Guid JobID => Row.Get<Assignment, Guid>(c => c.JobLink.ID);
         public string JobNumber => Row.Get<Assignment, String>(c => c.JobLink.JobNumber);
         public string JobName => Row.Get<Assignment, String>(c => c.JobLink.Name);
-        
+
         public Guid TaskID => Row.Get<Assignment, Guid>(c => c.Task.ID);
         public int TaskNumber => Row.Get<Assignment, int>(c => c.Task.Number);
         public string TaskName => Row.Get<Assignment, String>(c => c.Task.Title);
-        
+
         public String Subject => string.Format("{0}{1} {2}",
-            Row.Get<Assignment, int>(c => c.Number), 
-            Row.Get<Assignment,Guid>(c=>c.JobLink.ID) != Guid.Empty
+            Row.Get<Assignment, int>(c => c.Number),
+            Row.Get<Assignment, Guid>(c => c.JobLink.ID) != Guid.Empty
                 ? $"({Row.Get<Assignment, String>(c => c.JobLink.JobNumber)})"
                 : "",
             Row.Get<Assignment, String>(c => c.Title));
-        
+
         public string Notes => Row.Get<Assignment, String>(c => c.Description);
-        
-        public DateTime StartTime =>
-            Row.Get<Assignment, DateTime>(c => c.Date).Add(Row.Get<Assignment, TimeSpan>(c => c.Start));
 
-        public DateTime EndTime =>
-            Row.Get<Assignment, DateTime>(c => c.Date).Add(Row.Get<Assignment, TimeSpan>(c => c.Finish));
+        public DateTime StartTime
+        {
+            get
+            {
+                var startspan = Row.Get<Assignment, TimeSpan>(c => c.Actual.Start);
+                if (startspan.TotalMinutes != 0)
+                    return Row.Get<Assignment, DateTime>(c => c.Date).Add(Row.Get<Assignment, TimeSpan>(c => c.Actual.Start));
+                else
+                    return Row.Get<Assignment, DateTime>(c => c.Date).Add(Row.Get<Assignment, TimeSpan>(c => c.Booked.Start));
+            }
+        }
+
+
+        public DateTime EndTime
+        {
+            get
+            {
+                var finishspan = Row.Get<Assignment, TimeSpan>(c => c.Actual.Finish);
+                if (finishspan.TotalMinutes != 0)
+                    return Row.Get<Assignment, DateTime>(c => c.Date).Add(Row.Get<Assignment, TimeSpan>(c => c.Actual.Finish));
+                else
+                    return Row.Get<Assignment, DateTime>(c => c.Date).Add(Row.Get<Assignment, TimeSpan>(c => c.Booked.Finish));
+            }
+        }
 
         public bool Completed => !Row.Get<Assignment, DateTime>(c => c.Completed).IsEmpty();
 
@@ -72,7 +91,7 @@ namespace comal.timesheets
             get
             {
                 var color = Row.Get<Assignment, String>(c => c.ActivityLink.Color);
-                return !String.IsNullOrWhiteSpace(color) 
+                return !String.IsNullOrWhiteSpace(color)
                     ? Color.FromHex(color)
                     : Color.Silver;
             }
@@ -82,7 +101,6 @@ namespace comal.timesheets
         public Color TextColor => Color.Black;
 
         public ObservableCollection<object> ResourceIds => new ObservableCollection<object>() { Row.Get<Assignment, Guid>(c => c.EmployeeLink.ID) };
-
     }
 
 }