// dch rkl 10/26/2016 include schedule detail
        //public ClockOutPage(App_WorkTicket workTicket)
        public ClockOutPage(App_WorkTicket workTicket, App_ScheduledAppointment scheduleDetail)
        {
            InitializeComponent();

            _vm = new ClockOutPageViewModel(workTicket);

            _ciOptions = App.Database.GetCIOptions();

            // dch rkl 10/26/2016 return to ticket details instead of scheduled ticket list on cancel
            _scheduleDetail = scheduleDetail;

            // dch rkl 11/30/2016 display coverage checkboxes
            _workTicket = workTicket;

            // dch rkl 12/02/2016 Ticket Details

            // Get Current Technician
            JT_Technician technician = App.Database.GetCurrentTechnicianFromDb();

            // Service Ticket
            textServiceTicket.Content = _scheduleDetail.ServiceTicketNumber;

            // Employee Number and Name
            textEmployeeNumber.Content = technician.FormattedTechnicianNo;
            textEmployeeName.Content   = string.Format("{0} {1}", technician.FirstName, technician.LastName);

            // Set Coverage Checkboxes
            // Warranty Repair
            if (_workTicket.DtlWarrantyRepair == "Y")
            {
                switchWarrRepair.IsChecked = true;
            }

            // Labor Coverred on Warranty
            bool bIsChkd = false;

            if (_workTicket.StatusDate != null && _workTicket.RepairItem.MfgLaborWarrantyPeriod != null)
            {
                TimeSpan tsDateDiff = _workTicket.RepairItem.MfgLaborWarrantyPeriod.Subtract(_workTicket.StatusDate);
                if (tsDateDiff.TotalDays > 0 && _workTicket.DtlWarrantyRepair == "Y")
                {
                    switchLaborCovWarr.IsChecked = true;
                    bIsChkd = true;
                }
            }
            if (_workTicket.StatusDate != null && _workTicket.RepairItem.IntLaborWarrantyPeriod != null)
            {
                TimeSpan tsDateDiff = _workTicket.RepairItem.IntLaborWarrantyPeriod.Subtract(_workTicket.StatusDate);
                if (tsDateDiff.TotalDays > 0 && _workTicket.DtlWarrantyRepair == "Y")
                {
                    switchLaborCovWarr.IsChecked = true;
                    bIsChkd = true;
                }
            }

            // Service Agreement Repair
            if (_workTicket.DtlCoveredOnContract == "Y")
            {
                switchSvcAgrRepair.IsChecked = true;
            }

            // LLabor Covered on Service Agreement
            if (_workTicket.IsPreventativeMaintenance && _workTicket.ServiceAgreement.IsPMLaborCovered)
            {
                switchLaborCovSvcAgr.IsChecked = true;
            }
            else if (_workTicket.IsPreventativeMaintenance == false && _workTicket.IsServiceAgreementRepair && _workTicket.ServiceAgreement.IsLaborCovered)
            {
                switchLaborCovSvcAgr.IsChecked = true;
            }

            // Billable Picker
            pickerBillable.ItemsSource = _vm.BillableList;

            // Start Time
            DateTime dtStartDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day) + _vm.StartTime;

            if (App.Database.GetApplicationSettings().TwentyFourHourTime)
            {
                textStartTime.Text = dtStartDateTime.ToString("HH:mm");
            }
            else
            {
                textStartTime.Text = dtStartDateTime.ToString("hh:mm tt");
            }

            // Start Date
            textStartDate.Text = technician.CurrentStartDate.ToShortDateString();

            // Depart Time
            textEndDate.Text = DateTime.Now.ToShortDateString();
            if (App.Database.GetApplicationSettings().TwentyFourHourTime)
            {
                textDepartTime.Text = DateTime.Now.ToString("HH:mm");
            }
            else
            {
                textDepartTime.Text = DateTime.Now.ToString("hh:mm tt");
            }

            // dch rkl 01/23/2017 If Time Tracker Options is "Y", they enter start / end time.If "N", they enter hours. BEGIN
            // bk rkl 02/01/2017 moving north of sethoursbilled call
            _captureTimeInTimeTracker = "N";
            _MinHourlyCostIncrement   = 0;
            JT_TimeTrackerOptions tto = App.Database.GetTimeTrackerOptions();

            if (tto != null && tto.CaptureTimeInTimeTracker != null)
            {
                _captureTimeInTimeTracker = tto.CaptureTimeInTimeTracker;
                _MinHourlyCostIncrement   = tto.MinHourlyCostIncrement;
                if (_captureTimeInTimeTracker == "O")
                {
                    _captureTimeInTimeTracker = "Y";
                }
            }
            // Set Hours Billed
            if (textStartTime.Text != null && textDepartTime.Text != null)
            {
                SetHoursBilled();
            }

            // Technician Status
            // dch rkl 01/16/2017 If there is no value for the Default Depart Status Code, use the technician's current status BEGIN
            string statusCode = _vm.DefaultDepartStatusCode;

            if (statusCode == null || statusCode.Trim().Length == 0)
            {
                statusCode = technician.CurrentStatus;
            }
            // dch rkl 01/16/2017 If there is no value for the Default Depart Status Code, use the technician's current status END
            pickerTechnicianStatus.ItemsSource = _vm.TechnicianStatusList;
            for (int i = 0; i < pickerTechnicianStatus.Items.Count; i++)
            {
                // dch rkl 01/16/2017 If there is no value for the Default Depart Status Code, use the technician's current status BEGIN
                //if (((JT_TechnicianStatus)pickerTechnicianStatus.Items[i]).StatusDescription == _vm.DefaultDepartStatusCodeDescription)
                if (((JT_TechnicianStatus)pickerTechnicianStatus.Items[i]).StatusCode == statusCode)
                // dch rkl 01/16/2017 If there is no value for the Default Depart Status Code, use the technician's current status END
                {
                    pickerTechnicianStatus.SelectedIndex = i;
                    break;
                }
            }

            // Ticket Status
            pickerTicketStatus.ItemsSource   = _vm.ServiceTicketStatusList;
            pickerTicketStatus.SelectedValue = _vm.DefaultServiceTicketStatusCode;

            // Activity Code
            pickerActivityCode.ItemsSource   = _vm.ActivityCodeList;
            pickerActivityCode.SelectedValue = _vm.DefaultActivityCode;

            // Department
            pickerDepartment.ItemsSource = _vm.DepartmentCodesList;
            JT_ActivityCode dfltActCode = new JT_ActivityCode();

            if (_vm.DefaultActivityCode != null)
            {
                dfltActCode = App.Database.GetActivityCodeFromDB(_vm.DefaultActivityCode);
            }
            if (dfltActCode != null)
            {
                pickerDepartment.SelectedValue = dfltActCode.DeptWorkedIn;
            }

            // Earnings Code
            List <JT_EarningsCode> lsEarnCd = new List <Models.JT_EarningsCode>();

            foreach (JT_EarningsCode earncd in _vm.EarningsCodeList)
            {
                // Only include types of Regular or Overtime
                if (earncd.TypeOfEarnings == "O" || earncd.TypeOfEarnings == "R")
                {
                    earncd.EarningsDeductionDesc = string.Format("{0} - {1}", earncd.EarningsCode, earncd.EarningsDeductionDesc);
                    lsEarnCd.Add(earncd);
                }
            }
            pickerEarningsCode.ItemsSource = lsEarnCd;

            // dch rkl 11/01/2016 make sure default earning code is not null
            if (_vm.DefaultEarningCode != null)
            {
                pickerEarningsCode.SelectedValue = _vm.DefaultEarningCode;
            }
            else
            {
                pickerEarningsCode.SelectedIndex = 0;
            }

            // Meter Reading
            // dch rkl 11/1/2016 per Jeanne, hide the meter reading if JT_ServiceAgreementPMDetail.Basis = "M" BEGIN
            if (_vm.WorkTicket.ServiceAgreement != null && _vm.WorkTicket.ServiceAgreement.PmDetail != null &&
                _vm.WorkTicket.ServiceAgreement.PmDetail.Basis != null && _vm.WorkTicket.ServiceAgreement.PmDetail.Basis == "M")
            {
                labelMeterReading.Visibility  = Visibility.Visible;
                editorMeterReading.Visibility = Visibility.Visible;
            }
            else
            {
                labelMeterReading.Visibility  = Visibility.Hidden;
                editorMeterReading.Visibility = Visibility.Hidden;
            }
            // dch rkl 11/1/2016 per Jeanne, hide the meter reading if JT_ServiceAgreementPMDetail.Basis = "M" END

            // Set Ref Rate
            SetRefRate();

            // Work Performed
            editorWorkPerformed.MaxHeight = editorWorkPerformed.MinHeight;


            if (_captureTimeInTimeTracker == "Y")
            {
                // Enter start/end time
                textStartDate.IsEnabled     = true;
                textStartTime.IsEnabled     = true;
                textEndDate.IsEnabled       = true;
                textDepartTime.IsEnabled    = true;
                editorHoursWorked.IsEnabled = false;
            }
            else
            {
                // Enter hours
                textStartDate.IsEnabled     = false;
                textStartDate.Text          = "";
                textStartTime.IsEnabled     = false;
                textStartTime.Text          = "";
                textEndDate.IsEnabled       = false;
                textEndDate.Text            = "";
                textDepartTime.IsEnabled    = false;
                textDepartTime.Text         = "";
                editorHoursWorked.IsEnabled = true;
            }
            // dch rkl 01/23/2017 If Time Tracker Options is "Y", they enter start / end time.If "N", they enter hours. END

            // dch rkl 01/12/2017 Set Tab Indexes
            textStartDate.TabIndex          = 0;
            textStartTime.TabIndex          = 1;
            textEndDate.TabIndex            = 2;
            textDepartTime.TabIndex         = 3;
            editorHoursWorked.TabIndex      = 4;
            pickerBillable.TabIndex         = 5;
            editorHoursBilled.TabIndex      = 6;
            editorBillableRate.TabIndex     = 7;
            pickerTechnicianStatus.TabIndex = 8;
            pickerTicketStatus.TabIndex     = 9;
            pickerActivityCode.TabIndex     = 10;
            pickerDepartment.TabIndex       = 11;
            pickerEarningsCode.TabIndex     = 12;
            editorMeterReading.TabIndex     = 13;
            editorWorkPerformed.TabIndex    = 14;
            buttonClockout.TabIndex         = 15;
            buttonCancel.TabIndex           = 16;
        }
        public ClockOutPage(App_WorkTicket workTicket)
        {
            // Set the page title.
            //Title = "Clock Out";

            _vm = new ClockOutPageViewModel(workTicket);


            Color asbestos = Color.FromHex("#7f8c8d");

            BackgroundColor        = Color.White;
            _labelTitle            = new Xamarin.Forms.Label();
            _labelTitle.Text       = "CLOCK OUT";
            _labelTitle.FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null);
            _labelTitle.FontSize   = 22;
            _labelTitle.TextColor  = Color.White;
            _labelTitle.HorizontalTextAlignment = TextAlignment.Center;
            _labelTitle.VerticalTextAlignment   = TextAlignment.Center;

            Grid titleLayout = new Grid()
            {
                BackgroundColor   = Color.FromHex("#2980b9"),
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest     = 80
            };

            titleLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            titleLayout.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            titleLayout.Children.Add(_labelTitle, 0, 0);

            Label lblServiceTicket = new Label();

            lblServiceTicket.TextColor = asbestos;
            lblServiceTicket.Text      = _vm.ScheduleDetail.ServiceTicketNumber;

            JT_Technician technician = App.Database.GetCurrentTechnicianFromDb();

            Label lblEmployeeNo = new Label();

            lblEmployeeNo.TextColor = asbestos;
            lblEmployeeNo.Text      = technician.FormattedTechnicianNo; //_vm.CurrentTechnician.FormattedTechnicianNo;

            Label lblEmployeeName = new Label();

            lblEmployeeName.TextColor = asbestos;
            lblEmployeeName.Text      = string.Format("{0} {1}", technician.FirstName, technician.LastName); //_vm.CurrentTechnician.FirstName + " " + _vm.CurrentTechnician.LastName;

            Grid clockoutLayout = new Grid();

            clockoutLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });
            clockoutLayout.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star)
            });

            // service ticket line
            clockoutLayout.Children.Add(new Label()
            {
                Text      = "Service Ticket", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor = asbestos
            }, 0, 0);
            Grid.SetColumnSpan(lblServiceTicket, 3);
            clockoutLayout.Children.Add(lblServiceTicket, 1, 0);
            // employee number
            clockoutLayout.Children.Add(new Label()
            {
                Text      = "Employee Number", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor = asbestos
            }, 0, 1);
            clockoutLayout.Children.Add(lblEmployeeNo, 1, 1);
            clockoutLayout.Children.Add(lblEmployeeName, 2, 1);
            //  checks switches
            Switch switchWarrantyRepair = new Switch()
            {
                IsEnabled = false
            };

            if (_vm.WorkTicket.DtlWarrantyRepair == "Y")
            {
                switchWarrantyRepair.IsToggled = true;
            }
            clockoutLayout.Children.Add(new Label()
            {
                Text       = "Warranty Repair", TextColor = asbestos,
                FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null), FontSize = 12
            }, 0, 2);
            clockoutLayout.Children.Add(switchWarrantyRepair, 1, 2);
            bool isChkd = false;

            switchLaborCoveredWarranty = new Switch()
            {
                IsEnabled = false
            };
            if (_vm.WorkTicket.StatusDate != null && _vm.WorkTicket.RepairItem.MfgLaborWarrantyPeriod != null)
            {
                TimeSpan tsDateDiff = _vm.WorkTicket.RepairItem.MfgLaborWarrantyPeriod.Subtract(_vm.WorkTicket.StatusDate);
                if (tsDateDiff.TotalDays > 0 && _vm.WorkTicket.DtlWarrantyRepair == "Y")
                {
                    switchLaborCoveredWarranty.IsToggled = true;
                    isChkd = true;
                }
            }
            if (_vm.WorkTicket.StatusDate != null && _vm.WorkTicket.RepairItem.IntLaborWarrantyPeriod != null)
            {
                TimeSpan tsDateDiff = _vm.WorkTicket.RepairItem.IntLaborWarrantyPeriod.Subtract(_vm.WorkTicket.StatusDate);
                if (tsDateDiff.TotalDays > 0 && _vm.WorkTicket.DtlWarrantyRepair == "Y")
                {
                    switchLaborCoveredWarranty.IsToggled = true;
                    isChkd = true;
                }
            }
            clockoutLayout.Children.Add(new Label()
            {
                Text     = "Labor Covered on Warranty", TextColor = asbestos, FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                FontSize = 12
            }, 2, 2);
            clockoutLayout.Children.Add(switchLaborCoveredWarranty, 3, 2);
            Switch switchServiceAgreementRepair = new Switch()
            {
                IsEnabled = false
            };

            if (_vm.WorkTicket.DtlCoveredOnContract == "Y")
            {
                switchServiceAgreementRepair.IsToggled = true;
            }
            clockoutLayout.Children.Add(new Label()
            {
                Text       = "Svc Agmt Repair", TextColor = asbestos,
                FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null), FontSize = 12
            }, 0, 3);
            clockoutLayout.Children.Add(switchServiceAgreementRepair, 1, 3);
            switchLaborCoveredSvcAgreement = new Switch()
            {
                IsEnabled = false
            };
            if (_vm.WorkTicket.IsPreventativeMaintenance && _vm.WorkTicket.ServiceAgreement.IsPMLaborCovered)
            {
                switchLaborCoveredSvcAgreement.IsToggled = true;
            }
            else if (_vm.WorkTicket.IsPreventativeMaintenance == false && _vm.WorkTicket.IsServiceAgreementRepair && _vm.WorkTicket.ServiceAgreement.IsLaborCovered)
            {
                switchLaborCoveredSvcAgreement.IsToggled = true;
            }
            clockoutLayout.Children.Add(new Label()
            {
                Text     = "Labor Covered on Svc Agmt", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                FontSize = 12, TextColor = asbestos
            }, 2, 3);
            clockoutLayout.Children.Add(switchLaborCoveredSvcAgreement, 3, 3);

            // date part of the grid
            _pickerBillable                       = new BindablePicker();
            _pickerBillable.ItemsSource           = _vm.BillableList;
            _pickerBillable.SelectedIndexChanged += _pickerBillable_SelectedIndexChanged;

            DateTime dtStartDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day) + _vm.StartTime;

            _pickerStartDate      = new DatePicker();
            _pickerStartDate.Date = technician.CurrentStartDate; //_vm.CurrentTechnician.CurrentStartDate;

            _pickerStartTime           = new TimePicker();
            _pickerStartTime.Time      = _vm.StartTime;
            _pickerStartTime.IsEnabled = false;
            clockoutLayout.Children.Add(new Label()
            {
                Text      = "Start Time", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor = asbestos
            }, 0, 4);
            clockoutLayout.Children.Add(_pickerStartDate, 1, 4);
            clockoutLayout.Children.Add(_pickerStartTime, 2, 4);

            _pickerDepartDate      = new DatePicker();
            _pickerDepartDate.Date = DateTime.Now;

            _pickerDepartTime = new TimePicker {
                Time = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second)
            };
            _pickerDepartTime.Unfocused += PickerDepartTime_Unfocused;

            if (App.Database.GetApplicationSettings().TwentyFourHourTime)
            {
                _pickerStartTime.Format  = "HH:mm";
                _pickerDepartTime.Format = "HH:mm";
            }
            //if (_pickerStartTime.Time != null && _pickerDepartTime.Time != null) {
            //    SetHoursBilled();
            //}
            clockoutLayout.Children.Add(new Label()
            {
                Text      = "Depart Time", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor = asbestos
            }, 0, 5);
            clockoutLayout.Children.Add(_pickerDepartDate, 1, 5);
            clockoutLayout.Children.Add(_pickerDepartTime, 2, 5);

            //hours worked
            clockoutLayout.Children.Add(new Label()
            {
                Text      = "Hours Worked", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor = asbestos
            }, 0, 6);
            _editorHoursWorked           = new Editor();
            _editorHoursWorked.Text      = Math.Round((_pickerDepartTime.Time - _pickerStartTime.Time).TotalHours, 2).ToString();
            _editorHoursWorked.Keyboard  = Keyboard.Numeric;
            _editorHoursWorked.IsEnabled = false;
            clockoutLayout.Children.Add(_editorHoursWorked, 1, 6);
            Grid.SetColumnSpan(_pickerBillable, 2);
            _pickerBillable.SetBinding(BindablePicker.DisplayPropertyProperty, "BillableDesc");
            clockoutLayout.Children.Add(_pickerBillable, 2, 6);

            //hours billed
            clockoutLayout.Children.Add(new Label()
            {
                Text      = "Billable Hours", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor = asbestos
            }, 0, 7);
            _editorHoursBilled          = new Editor();
            _editorHoursBilled.Text     = Math.Round((_pickerDepartTime.Time - _pickerStartTime.Time).TotalHours, 2).ToString();
            _editorHoursBilled.Keyboard = Keyboard.Numeric;
            clockoutLayout.Children.Add(_editorHoursBilled, 1, 7);
            clockoutLayout.Children.Add(new Label()
            {
                Text      = "Ref Rate", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor = asbestos
            }, 2, 7);
            _editorRefRate = new Editor()
            {
                IsEnabled = false
            };
            clockoutLayout.Children.Add(_editorRefRate, 3, 7);

            // rates
            clockoutLayout.Children.Add(new Label()
            {
                Text      = "Billable Rate", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor = asbestos
            }, 0, 8);
            _editorBillableRate = new Editor()
            {
                IsEnabled = false
            };
            clockoutLayout.Children.Add(_editorBillableRate, 1, 8);
            clockoutLayout.Children.Add(new Label()
            {
                Text      = "Billable Amount", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor = asbestos
            }, 2, 8);
            _editorBillableAmount = new Editor()
            {
                IsEnabled = false
            };
            clockoutLayout.Children.Add(_editorBillableAmount, 3, 8);

            _pickerTechnicianStatus = new BindablePicker {
                Title = "Technician Status", ItemsSource = _vm.TechnicianStatusList
            };
            _pickerTechnicianStatus.SetBinding(BindablePicker.DisplayPropertyProperty, "StatusDescription");
            for (int i = 0; i < _pickerTechnicianStatus.Items.Count; i++)
            {
                if (_pickerTechnicianStatus.Items[i] == _vm.DefaultDepartStatusCodeDescription)
                {
                    _pickerTechnicianStatus.SelectedIndex = i;
                    break;
                }
            }
            clockoutLayout.Children.Add(new Label()
            {
                Text      = "Technician Status", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor = asbestos
            }, 0, 9);
            Grid.SetColumnSpan(_pickerTechnicianStatus, 3);
            clockoutLayout.Children.Add(_pickerTechnicianStatus, 1, 9);

            _pickerTicketStatus = new BindablePicker {
                Title = "Service Ticket Status", ItemsSource = _vm.ServiceTicketStatusList
            };
            _pickerTicketStatus.SetBinding(BindablePicker.DisplayPropertyProperty, "Description");

            /*for (int i = 0; i < _pickerTicketStatus.Items.Count; i++) {
             *  if (_pickerTicketStatus.Items[i].Substring(0, 3) == _vm.DefaultServiceTicketStatusCode) {
             *      _pickerTicketStatus.SelectedIndex = i;
             *      break;
             *  }
             * }*/
            clockoutLayout.Children.Add(new Label()
            {
                Text      = "Ticket Status", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor = asbestos
            }, 0, 10);
            Grid.SetColumnSpan(_pickerTicketStatus, 3);
            clockoutLayout.Children.Add(_pickerTicketStatus, 1, 10);

            _pickerActivityCode = new BindablePicker {
                Title = "Activity Code", ItemsSource = _vm.ActivityCodeList
            };
            _pickerActivityCode.SetBinding(BindablePicker.DisplayPropertyProperty, "ActivityDescription");
            for (int i = 0; i < _pickerActivityCode.Items.Count; i++)
            {
                if (_pickerActivityCode.Items[i] == _vm.DefaultActivityCode)
                {
                    _pickerActivityCode.SelectedIndex = i;
                    break;
                }
            }
            clockoutLayout.Children.Add(new Label()
            {
                Text      = "Activity Code", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor = asbestos
            }, 0, 11);
            Grid.SetColumnSpan(_pickerActivityCode, 3);
            clockoutLayout.Children.Add(_pickerActivityCode, 1, 11);

            _pickerDepartment = new BindablePicker {
                Title = "Department", ItemsSource = _vm.DepartmentCodesList
            };
            _pickerDepartment.SetBinding(BindablePicker.DisplayPropertyProperty, "MiscellaneousCode");
            JT_ActivityCode dfltActCode = new JT_ActivityCode();

            if (_vm.DefaultActivityCode != null)
            {
                dfltActCode = App.Database.GetActivityCodeFromDB(_vm.DefaultActivityCode);
            }
            if (dfltActCode != null)
            {
                for (int i = 0; i < _pickerDepartment.Items.Count; i++)
                {
                    if (_pickerDepartment.Items[i] == dfltActCode.DeptWorkedIn)
                    {
                        _pickerDepartment.SelectedIndex = i;
                        break;
                    }
                }
            }
            clockoutLayout.Children.Add(new Label()
            {
                Text      = "Department", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor = asbestos
            }, 0, 12);
            Grid.SetColumnSpan(_pickerDepartment, 3);
            clockoutLayout.Children.Add(_pickerDepartment, 1, 12);

            _pickerEarningsCode = new BindablePicker {
                Title = "Earnings Code", ItemsSource = _vm.EarningsCodeList
            };
            _pickerEarningsCode.SetBinding(BindablePicker.DisplayPropertyProperty, "EarningsDeductionDesc");

            /*for (int i = 0; i < _pickerEarningsCode.Items.Count; i++) {
             *  if (_pickerEarningsCode.Items[i] == _vm.DefaultEarningCode) {
             *      _pickerEarningsCode.SelectedIndex = i;
             *      break;
             *  }
             * }*/
            clockoutLayout.Children.Add(new Label()
            {
                Text      = "Earnings Code", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor = asbestos
            }, 0, 13);
            Grid.SetColumnSpan(_pickerEarningsCode, 3);
            clockoutLayout.Children.Add(_pickerEarningsCode, 1, 13);

            _editorMeterReading               = new Editor();
            _editorMeterReading.Keyboard      = Keyboard.Numeric;
            _editorMeterReading.HeightRequest = 100;
            _editorMeterReading.IsEnabled     = _vm.IsRepairItemAnEquipmentAsset;
            clockoutLayout.Children.Add(new Label()
            {
                Text      = "Meter Reading", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor = asbestos
            }, 0, 14);
            Grid.SetColumnSpan(_editorMeterReading, 3);
            clockoutLayout.Children.Add(_editorMeterReading, 1, 14);

            _editorWorkPerformed = new Editor();
            _editorWorkPerformed.HeightRequest = 100;
            _editorWorkPerformed.TextChanged  += EditorWorkPerformed_TextChanged;
            clockoutLayout.Children.Add(new Label()
            {
                Text      = "Work Performed", FontFamily = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor = asbestos
            }, 0, 15);
            Grid.SetColumnSpan(_editorWorkPerformed, 3);
            clockoutLayout.Children.Add(_editorWorkPerformed, 1, 15);

            // create a "clock out" button to go back
            Xamarin.Forms.Button buttonClockOut = new Button()
            {
                Text              = "Clock Out",
                FontFamily        = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor         = Color.White,
                BackgroundColor   = asbestos,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };
            buttonClockOut.Clicked += ButtonClockOut_Clicked;

            // create a "cancel" button to go back
            Xamarin.Forms.Button buttonCancel = new Button()
            {
                Text              = "Cancel",
                FontFamily        = Device.OnPlatform("OpenSans-Bold", "sans-serif-black", null),
                TextColor         = Color.White,
                BackgroundColor   = Color.FromHex("#E74C3C"),
                HorizontalOptions = LayoutOptions.FillAndExpand
            };
            buttonCancel.Clicked += buttonCancel_Clicked;

            Content = new StackLayout {
                Children =
                {
                    titleLayout,
                    new StackLayout
                    {
                        Orientation = StackOrientation.Vertical,
                        Padding     = 30,
                        Children    =
                        {
                            clockoutLayout,
                            buttonClockOut,
                            buttonCancel
                        }
                    }
                }
            };
        }