Esempio n. 1
0
        // dch rkl 11/15/2016 Add clock out date
        // dch rkl 01/23/2017 Check value of CaptureTimeInTimeTracker to see if hours or timespan is entered
        // dch rkl 01/23/2017 Include Service Agreement Code
        // bk  rkl 01/26/2017 adjust to only include transaction date
        public void ClockOut(TimeSpan departTime, JT_TechnicianStatus technicianStatus, JT_MiscellaneousCodes serviceTicketStatus,
                             JT_ActivityCode activityCode, string departmentWorked, JT_EarningsCode earningsCode, double hoursBilled,
                             double meterReading, string workPerformedText, string clockOutDate, string captureTimeInTimeTracker,
                             double hoursWorked, string svcAgmtContractCode, string billingType)
        {
            // dch rkl 12/07/2016 catch exception
            try
            {
                if (captureTimeInTimeTracker == "Y")
                {
                    // dch rkl 11/15/2016 Add clock out date
                    //DateTime clockOutTime = DateTime.Today;
                    DateTime clockOutTime = DateTime.Parse(clockOutDate);

                    clockOutTime = clockOutTime.Add(departTime);

                    // dch rkl 02/03/2017 Include clockOutDate
                    //App.Database.ClockOut(App.CurrentTechnician, _workTicket, clockOutTime, technicianStatus, serviceTicketStatus,
                    //    activityCode.ActivityCode, departmentWorked, earningsCode, hoursBilled, meterReading, workPerformedText, svcAgmtContractCode);
                    App.Database.ClockOut(App.CurrentTechnician, _workTicket, clockOutTime, technicianStatus, serviceTicketStatus,
                                          activityCode.ActivityCode, departmentWorked, earningsCode, hoursBilled, hoursWorked, meterReading, workPerformedText,
                                          svcAgmtContractCode, clockOutDate, billingType);
                }
                else
                {
                    App.Database.ClockOut(App.CurrentTechnician, _workTicket, technicianStatus, serviceTicketStatus, activityCode.ActivityCode,
                                          departmentWorked, earningsCode, hoursBilled, meterReading, workPerformedText, hoursWorked, svcAgmtContractCode, billingType);
                }
            }
            catch (Exception exception)
            {
                App.sendException(exception, "TechDashboard.ClockOutPageViewModel.ClockOut()");
            }
        }
        // dch rkl 12/02/2016 Set Billable Rate
        private void SetBillableRate()
        {
            decimal billingRate = 0;

            string sBillable = "";

            if (pickerBillable.SelectedIndex > -1 && pickerBillable.SelectedValue != null)
            {
                sBillable = pickerBillable.SelectedValue.ToString();
            }

            string sActivityCode    = "";
            string sBillingMiscCode = "";

            if (pickerActivityCode.SelectedIndex > -1 && pickerActivityCode.SelectedValue != null)
            {
                sActivityCode = pickerActivityCode.SelectedValue.ToString();
            }
            if (sActivityCode.Length > 0)
            {
                JT_ActivityCode activityCode = App.Database.GetActivityCodeFromDB(sActivityCode);
                if (activityCode != null && activityCode.BillingMiscCode != null)
                {
                    sBillingMiscCode = activityCode.BillingMiscCode;
                }
            }

            if (sBillable != "B")
            {
                billingRate = 0;
            }
            else if ((bool)switchLaborCovSvcAgr.IsChecked && _workTicket.ServiceAgreement.BillingType == "F" &&
                     _workTicket.DtlCoverageExceptionCode == null && sBillingMiscCode == "")
            {
                billingRate = 0;
            }
            else if (_workTicket.ServiceAgreement.IsLaborCovered == true && _workTicket.IsCoveredOnContract == true)
            {
                billingRate = 0;
            }
            else if ((bool)switchLaborCovWarr.IsChecked && _workTicket.DtlCoverageExceptionCode == null &&
                     _workTicket.SE_OverridePricing != "Y")
            {
                billingRate = 0;
            }
            else
            {
                billingRate = Decimal.Parse(editorRefRate.Text.Replace("$", ""));
            }

            // Set the value in the rate box
            editorBillableRate.Text = billingRate.ToString("C2");

            // Set the value in the Billable Amount Box
            decimal hours;

            decimal.TryParse(editorHoursBilled.Text.Replace("$", ""), out hours);
            editorBillableAmount.Text = Math.Round(billingRate * hours, 2, MidpointRounding.AwayFromZero).ToString("C2");
        }
        private void SetRefRate()
        {
            decimal billingRate = 0;

            decimal         billingRateMultiplier = 1;
            JT_ActivityCode activityCode          = (JT_ActivityCode)_pickerActivityCode.SelectedItem;

            if (activityCode != null)
            {
                billingRateMultiplier = activityCode.BillingRateMultiplier;
                if (billingRateMultiplier == 0)
                {
                    billingRateMultiplier = 1;
                }
            }

            if (_vm.WorkTicket.DtlCoverageExceptionCode != null && _vm.WorkTicket.DtlCoverageExceptionCode.Trim().Length > 0)
            {
                billingRate = _vm.WorkTicket.DtlCoverageExceptionFixedRate;
            }
            if (_vm.WorkTicket.IsPreventativeMaintenance)
            {
                billingRate = Math.Round(_vm.WorkTicket.ServiceAgreement.PmDetail.Rate * billingRateMultiplier, 2, MidpointRounding.AwayFromZero);
            }
            else
            {
                if (_vm.WorkTicket.ServiceAgreement.DetailRate != 0)
                {
                    billingRate = Math.Round(_vm.WorkTicket.ServiceAgreement.DetailRate * billingRateMultiplier, 2, MidpointRounding.AwayFromZero);
                }
                else
                {
                    billingRate = Math.Round(_vm.WorkTicket.ServiceAgreement.StandardLaborRate * billingRateMultiplier, 2, MidpointRounding.AwayFromZero);
                }
            }

            if (activityCode != null)
            {
                App_Customer            customer     = App.Database.GetAppCustomer(_vm.WorkTicket);
                JT_CustomerBillingRates custBillRate = App.Database.GetJT_CustomerBillingRate(customer.ARDivisionNo, customer.CustomerNo, activityCode.ActivityCode);
                if (custBillRate != null)
                {
                    billingRate = Math.Round(custBillRate.BillRatePerHour * billingRateMultiplier, 2, MidpointRounding.AwayFromZero);
                }
            }

            if (billingRate == 0)
            {
                JT_Technician technician = App.Database.GetCurrentTechnicianFromDb();
                billingRate = Math.Round(technician.StandardBillingRate * billingRateMultiplier, 2, MidpointRounding.AwayFromZero);
            }

            _editorRefRate.Text = billingRate.ToString("C2");

            SetBillableRate();
        }
        private void SetBillableRate()
        {
            decimal billingRate = 0;
            string  sBillable   = "";

            ClockOutPageViewModel.App_Billable appBillable = (ClockOutPageViewModel.App_Billable)_pickerBillable.SelectedItem;

            sBillable = appBillable.BillableFlag;

            string          sBillingMiscCode = "";
            JT_ActivityCode activityCode     = (JT_ActivityCode)_pickerActivityCode.SelectedItem;

            if (activityCode != null)
            {
                if (activityCode.BillingMiscCode != null)
                {
                    sBillingMiscCode = activityCode.BillingMiscCode;
                }
            }

            if (sBillable != "B")
            {
                billingRate = 0;
            }
            else if ((bool)switchLaborCoveredSvcAgreement.IsToggled &&
                     _vm.WorkTicket.ServiceAgreement.BillingType == "F" &&
                     _vm.WorkTicket.DtlCoverageExceptionCode == null &&
                     sBillingMiscCode == "")
            {
                billingRate = 0;
            }
            else if (_vm.WorkTicket.ServiceAgreement.IsLaborCovered == true &&
                     _vm.WorkTicket.IsCoveredOnContract == true)
            {
                billingRate = 0;
            }
            else if ((bool)switchLaborCoveredWarranty.IsToggled && _vm.WorkTicket.DtlCoverageExceptionCode == null &&
                     _vm.WorkTicket.SE_OverridePricing != "Y")
            {
                billingRate = 0;
            }
            else
            {
                billingRate = Decimal.Parse(_editorRefRate.Text.Replace("$", ""));
            }

            // Set the value in the rate box
            _editorBillableRate.Text = billingRate.ToString("C2");

            // Set the value in the Billable Amount Box
            decimal hours;

            decimal.TryParse(_editorHoursBilled.Text.Replace("$", ""), out hours);
            _editorBillableAmount.Text = Math.Round(billingRate * hours, 2, MidpointRounding.AwayFromZero).ToString("C2");
        }
Esempio n. 5
0
        public JT_ActivityCode GetActivityCodeFromDB(string activityCode)
        {
            JT_ActivityCode codeToReturn = null;

            lock (_locker)
            {
                if (activityCode != null)
                {
                    codeToReturn =
                        _database.Table <JT_ActivityCode>().Where(
                            ac => (ac.ActivityCode == activityCode)
                            ).FirstOrDefault();
                }
            }

            return(codeToReturn);
        }
        // dch rkl 11/1/2016 use textbox instead of datetime picker for times END

        // dch rkl 11/22/2016 if activity code changed, set department to default for this activity code
        // If the department for the activity code is null/blank, use the employee department
        private void pickerActivityCode_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Set the Department
            string sActivityCode = "";

            if (pickerActivityCode.SelectedIndex > -1 && pickerActivityCode.SelectedValue != null)
            {
                sActivityCode = pickerActivityCode.SelectedValue.ToString();
            }
            JT_ActivityCode activityCode = App.Database.GetActivityCodeFromDB(sActivityCode);

            if (activityCode != null && activityCode.DeptWorkedIn != null)
            {
                pickerDepartment.SelectedValue = activityCode.DeptWorkedIn;
            }
            else
            {
                JT_Technician tech = App.Database.GetCurrentTechnicianFromDb();
                if (tech != null && tech.TechnicianDeptNo != null)
                {
                    pickerDepartment.SelectedValue = tech.TechnicianDeptNo;
                }
            }

            // Determine if the Billable Dropdown is enabled
            // An activity code is considered billable when a misc item code is assigned to the activity code
            if (activityCode != null && activityCode.BillingMiscCode != null && activityCode.BillingMiscCode.Trim().Length > 0)
            {
                // When a billable activity code is assigned to the activity code, the billing status dropdown is enabled.
                pickerBillable.IsEnabled = true;
                SetBillable();
            }
            else
            {
                // When a non-billable activity code is assigned to the activity code, the billing
                // status is disabled and set to no charge.
                pickerBillable.IsEnabled     = false;
                pickerBillable.SelectedValue = "N";
            }
        }
        // dch rkl 12/02/2016 Set Billable/Non-Billable Flag
        private void SetBillable()
        {
            pickerBillable.SelectedValue = "B";     // default to billable
            string sActivityCode = "";

            if (pickerActivityCode.SelectedIndex > -1 && pickerActivityCode.SelectedValue != null)
            {
                sActivityCode = pickerActivityCode.SelectedValue.ToString();
            }
            if (sActivityCode.Length > 0)
            {
                JT_ActivityCode activityCode = App.Database.GetActivityCodeFromDB(sActivityCode);
                if (activityCode.BillingMiscCode == null)
                {
                    pickerBillable.SelectedValue = "N";
                    pickerBillable.IsEnabled     = false;
                }
                else if (_workTicket.ServiceAgreement.BillingType != null && _workTicket.ServiceAgreement.BillingType == "P" &&
                         (bool)switchSvcAgrRepair.IsChecked)
                {
                    pickerBillable.SelectedValue = "N";
                }
                else if (_workTicket.ServiceAgreement.BillingType == "P" && (bool)switchSvcAgrRepair.IsChecked)
                {
                    pickerBillable.SelectedValue = "X";
                }
                else if (_workTicket.ServiceAgreement.IsLaborCovered == false && _workTicket.ServiceAgreement.BillingType != "T" &&
                         _workTicket.ServiceAgreement.BillingType != "P")
                {
                    pickerBillable.SelectedValue = "X";
                }
                else if (_workTicket.ServiceAgreement.BillingType == "F" && _workTicket.ServiceAgreement.IsLaborCovered == false)
                {
                    pickerBillable.SelectedValue = "N";
                }
            }
        }
        // dch rkl 12/02/2016 Set Ref Rate
        private void SetRefRate()
        {
            decimal billingRate = 0;

            string  sActivityCode         = "";
            decimal billingRateMultiplier = 1;

            if (pickerActivityCode.SelectedIndex > -1 && pickerActivityCode.SelectedValue != null)
            {
                sActivityCode = pickerActivityCode.SelectedValue.ToString();
            }
            if (sActivityCode.Length > 0)
            {
                JT_ActivityCode activityCode = App.Database.GetActivityCodeFromDB(sActivityCode);
                billingRateMultiplier = activityCode.BillingRateMultiplier;
                if (billingRateMultiplier == 0)
                {
                    billingRateMultiplier = 1;
                }
            }

            if (_workTicket.DtlCoverageExceptionCode != null && _workTicket.DtlCoverageExceptionCode.Trim().Length > 0)
            {
                billingRate = _workTicket.DtlCoverageExceptionFixedRate;
            }
            if (_workTicket.IsPreventativeMaintenance)
            {
                billingRate = Math.Round(_workTicket.ServiceAgreement.PmDetail.Rate * billingRateMultiplier, 2, MidpointRounding.AwayFromZero);
            }
            else
            {
                if (_workTicket.ServiceAgreement.DetailRate != 0)
                {
                    billingRate = Math.Round(_workTicket.ServiceAgreement.DetailRate * billingRateMultiplier, 2, MidpointRounding.AwayFromZero);
                }
                else
                {
                    billingRate = Math.Round(_workTicket.ServiceAgreement.StandardLaborRate * billingRateMultiplier, 2, MidpointRounding.AwayFromZero);
                }
            }

            // Look for customer billing rates
            if (sActivityCode.Trim().Length > 0)
            {
                App_Customer            customer     = App.Database.GetAppCustomer(_workTicket);
                JT_CustomerBillingRates custBillRate = App.Database.GetJT_CustomerBillingRate(customer.ARDivisionNo, customer.CustomerNo,
                                                                                              sActivityCode);
                if (custBillRate != null)
                {
                    billingRate = Math.Round(custBillRate.BillRatePerHour * billingRateMultiplier, 2, MidpointRounding.AwayFromZero);
                }
            }

            // Set Rate based on Technician
            if (billingRate == 0)
            {
                JT_Technician technician = App.Database.GetCurrentTechnicianFromDb();

                billingRate = Math.Round(technician.StandardBillingRate * billingRateMultiplier, 2, MidpointRounding.AwayFromZero);
            }

            // Set the value in the rate box
            editorRefRate.Text = billingRate.ToString("C2");

            // Billable Rate
            SetBillableRate();
        }
        // 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;
        }
        private void ButtonClockOut_Clicked(object sender, RoutedEventArgs e)
        {
            if (pickerTechnicianStatus.SelectedIndex < 0)
            {
                MessageBoxResult result = System.Windows.MessageBox.Show("Select a technician status.", "Status", MessageBoxButton.OK);
                if (result == MessageBoxResult.OK)
                {
                    return;
                }
            }
            if (pickerTicketStatus.SelectedIndex < 0)
            {
                MessageBoxResult result = System.Windows.MessageBox.Show("Select a ticket status.", "Status", MessageBoxButton.OK);
                if (result == MessageBoxResult.OK)
                {
                    return;
                }
            }
            if (pickerEarningsCode.SelectedIndex < 0)
            {
                MessageBoxResult result = System.Windows.MessageBox.Show("Select an earnings code.", "Status", MessageBoxButton.OK);
                if (result == MessageBoxResult.OK)
                {
                    return;
                }
            }
            if (pickerActivityCode.SelectedIndex < 0)
            {
                //await DisplayAlert("Activity Code", "Select an activity code.", "OK");
                //return;
                MessageBoxResult result = System.Windows.MessageBox.Show("Select an activity code.", "Status", MessageBoxButton.OK);
                if (result == MessageBoxResult.OK)
                {
                    return;
                }
            }

            // Validate Dates
            DateTime dtDepart    = DateTime.Now;
            double   hoursWorked = 0;

            // dch rkl 01/23/2017 captureTimeInTimeTracker == "Y", date and time must be entered
            if (_captureTimeInTimeTracker == "Y")
            {
                DateTime dtArrive;
                if (textStartTime.Text != null)
                {
                    if (DateTime.TryParse(textStartTime.Text, out dtArrive) == false)
                    {
                        MessageBoxResult result = System.Windows.MessageBox.Show("Enter a valid Arrive Date.", "Arrive Date", MessageBoxButton.OK);
                        if (result == MessageBoxResult.OK)
                        {
                            return;
                        }
                    }
                }
                else
                {
                    MessageBoxResult result = System.Windows.MessageBox.Show("Enter a valid Arrive Date.", "Arrive Date", MessageBoxButton.OK);
                    if (result == MessageBoxResult.OK)
                    {
                        return;
                    }
                }

                if (textDepartTime.Text != null)
                {
                    if (DateTime.TryParse(textDepartTime.Text, out dtDepart) == false)
                    {
                        MessageBoxResult result = System.Windows.MessageBox.Show("Enter a valid Depart Date.", "Depart Date", MessageBoxButton.OK);
                        if (result == MessageBoxResult.OK)
                        {
                            return;
                        }
                    }
                }
                else
                {
                    MessageBoxResult result = System.Windows.MessageBox.Show("Enter a valid Depart Date.", "Depart Date", MessageBoxButton.OK);
                    if (result == MessageBoxResult.OK)
                    {
                        return;
                    }
                }

                // dch rkl 02/03/2017 Capture hours worked, for validation
                if (editorHoursWorked != null)
                {
                    double.TryParse(editorHoursWorked.Text, out hoursWorked);
                }
            }
            else
            {
                // dch rkl 01/23/2017 captureTimeInTimeTracker == "N", hours must be entered
                if (editorHoursWorked != null)
                {
                    double.TryParse(editorHoursWorked.Text, out hoursWorked);
                }
                if (hoursWorked == 0)
                {
                    MessageBoxResult result = System.Windows.MessageBox.Show("Enter valid Hours Worked.", "Hours Worked", MessageBoxButton.OK);
                    if (result == MessageBoxResult.OK)
                    {
                        return;
                    }
                }
            }
            if (hoursWorked > 24)
            {
                MessageBoxResult result = System.Windows.MessageBox.Show("Time entry cannot exceed 24 hours.  Please adjust your Depart Date/Time and create separate Clock In/Clock Out for additional hours.", "Hours Worked", MessageBoxButton.OK);
                if (result == MessageBoxResult.OK)
                {
                    return;
                }
            }

            double meterReading = 0;
            double hoursBilled  = 0;

            JT_TechnicianStatus   selectedTechnicianStatus = pickerTechnicianStatus.SelectedItem as JT_TechnicianStatus;
            JT_MiscellaneousCodes selectedTicketStatus     = pickerTicketStatus.SelectedItem as JT_MiscellaneousCodes;
            JT_EarningsCode       selectedEarningsCode     = pickerEarningsCode.SelectedItem as JT_EarningsCode;
            JT_ActivityCode       selectedActivityCode     = pickerActivityCode.SelectedItem as JT_ActivityCode;

            try
            {
                if (_vm.IsRepairItemAnEquipmentAsset)
                {
                    meterReading = double.Parse(editorMeterReading.Text);
                }
                else
                {
                    meterReading = 0;
                }
            }
            catch
            {
                // empty
            }
            try
            {
                hoursBilled = double.Parse(editorHoursBilled.Text);
            }
            catch
            {
                // empty
            }

            // dch rkl 01/23/2017 captureTimeInTimeTracker == "Y", date and time must be entered
            if (_captureTimeInTimeTracker == "Y")
            {
                // dch rkl 02/03/2017 use arrive date
                //_vm.ClockOut(dtDepart.TimeOfDay, selectedTechnicianStatus, selectedTicketStatus, selectedActivityCode,
                //    pickerDepartment.SelectedValue.ToString(), selectedEarningsCode, hoursBilled, meterReading, editorWorkPerformed.Text,
                //    textEndDate.Text, _captureTimeInTimeTracker, hoursWorked, _vm.WorkTicket.ServiceAgreement.ServiceAgreementNumber);
                _vm.ClockOut(dtDepart.TimeOfDay, selectedTechnicianStatus, selectedTicketStatus, selectedActivityCode,
                             pickerDepartment.SelectedValue.ToString(), selectedEarningsCode, hoursBilled, meterReading, editorWorkPerformed.Text,
                             textStartDate.Text, _captureTimeInTimeTracker, hoursWorked, _vm.WorkTicket.ServiceAgreement.ServiceAgreementNumber);
            }
            else
            {
                TimeSpan ts = new TimeSpan();
                _vm.ClockOut(ts, selectedTechnicianStatus, selectedTicketStatus, selectedActivityCode,
                             pickerDepartment.SelectedValue.ToString(), selectedEarningsCode, hoursBilled, meterReading, editorWorkPerformed.Text,
                             "", _captureTimeInTimeTracker, hoursWorked, _vm.WorkTicket.ServiceAgreement.ServiceAgreementNumber);
            }

            ContentControl contentArea = (ContentControl)this.Parent;

            contentArea.Content = new SchedulePage();
        }
        protected async void ButtonClockOut_Clicked(object sender, EventArgs e)
        {
            if (_pickerTechnicianStatus.SelectedIndex < 0)
            {
                await DisplayAlert("Status", "Select a technician status.", "OK");

                return;
            }
            if (_pickerTicketStatus.SelectedIndex < 0)
            {
                await DisplayAlert("Status", "Select a ticket status.", "OK");

                return;
            }
            if (_pickerEarningsCode.SelectedIndex < 0)
            {
                await DisplayAlert("Earnings Code", "Select an earnings code.", "OK");

                return;
            }
            if (_pickerActivityCode.SelectedIndex < 0)
            {
                await DisplayAlert("Activity Code", "Select an activity code.", "OK");

                return;
            }

            DateTime dtDepart    = DateTime.Now;
            double   hoursWorked = 0;

            if (_captureTimeInTimeTracker == "Y")
            {
                DateTime dtArrive;
                if (_pickerStartDate.Date == null)
                {
                    await DisplayAlert("Arrive Date", "Enter a valid arrival date.", "OK");

                    return;
                }

                if (_pickerDepartDate.Date == null)
                {
                    await DisplayAlert("Depart Date", "Enter a valid departure date.", "OK");

                    return;
                }

                // dch rkl 02/03/2017 Capture hours worked, for validation
                if (_editorHoursWorked.Text != null)
                {
                    double.TryParse(_editorHoursWorked.Text, out hoursWorked);
                }
            }
            else
            {
                // dch rkl 01/23/2017 captureTimeInTimeTracker == "N", hours must be entered
                if (_editorHoursWorked.Text != null)
                {
                    double.TryParse(_editorHoursWorked.Text, out hoursWorked);
                }
                if (hoursWorked == 0)
                {
                    await DisplayAlert("Hours Worked", "Enter valid hours worked.", "OK");

                    return;
                }
            }
            if (hoursWorked > 24)
            {
                await DisplayAlert("Hours Worked", "Time entry cannot exceed 24 hours.  Please adjust your Depart Date/Time and create a separate Clock In/Clock Out for additional hours.", "OK");

                return;
            }

            double meterReading = 0;
            double hoursBilled  = 0;

            JT_TechnicianStatus   selectedTechnicianStatus = _pickerTechnicianStatus.SelectedItem as JT_TechnicianStatus;
            JT_MiscellaneousCodes selectedTicketStatus     = _pickerTicketStatus.SelectedItem as JT_MiscellaneousCodes;
            JT_EarningsCode       selectedEarningsCode     = _pickerEarningsCode.SelectedItem as JT_EarningsCode;
            JT_ActivityCode       selectedActivityCode     = _pickerActivityCode.SelectedItem as JT_ActivityCode;

            try
            {
                if (_vm.IsRepairItemAnEquipmentAsset)
                {
                    meterReading = double.Parse(_editorMeterReading.Text);
                }
                else
                {
                    meterReading = 0;
                }
            }
            catch
            {
                // empty
            }
            try
            {
                hoursBilled = double.Parse(_editorHoursBilled.Text);
            }
            catch
            {
                // empty
            }
            JT_MiscellaneousCodes deptCode = (JT_MiscellaneousCodes)_pickerDepartment.SelectedItem;

            ClockOutPageViewModel.App_Billable appBillable = (ClockOutPageViewModel.App_Billable)_pickerBillable.SelectedItem;

            if (_captureTimeInTimeTracker == "Y")
            {
                //_vm.ClockOut(_pickerDepartTime.Time, selectedTechnicianStatus, selectedTicketStatus, selectedActivityCode, string.Empty,
                //             selectedEarningsCode, hoursBilled, meterReading, _editorWorkPerformed.Text, _pickerDepartDate.Date.ToShortDateString());
                _vm.ClockOut(_pickerDepartTime.Time, selectedTechnicianStatus, selectedTicketStatus, selectedActivityCode, deptCode.MiscellaneousCode,
                             selectedEarningsCode, hoursBilled, meterReading, _editorWorkPerformed.Text, _pickerDepartDate.Date.ToShortDateString(), _captureTimeInTimeTracker,
                             hoursWorked, _vm.WorkTicket.ServiceAgreement.ServiceAgreementNumber, appBillable.BillableFlag);
            }
            else
            {
                _vm.ClockOut(new TimeSpan(), selectedTechnicianStatus, selectedTicketStatus, selectedActivityCode, deptCode.MiscellaneousCode,
                             selectedEarningsCode, hoursBilled, meterReading, _editorWorkPerformed.Text, "", _captureTimeInTimeTracker, hoursWorked,
                             _vm.WorkTicket.ServiceAgreement.ServiceAgreementNumber, appBillable.BillableFlag);
            }
            await Navigation.PopToRootAsync();
        }
        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
                        }
                    }
                }
            };
        }