public App_ErpOptions GetErpOptions()
        {
            App_ErpOptions erpOptions = null;

            lock (_locker)
            {
                JT_FieldServiceOptions fieldServiceOption  = GetFieldServiceOption();
                JT_TechnicianStatus    defaultArriveStatus = null;
                JT_TechnicianStatus    defaultDepartStatus = null;
                JT_MiscellaneousCodes  defaultServiceTicketArriveStatus = null;

                if (fieldServiceOption != null)
                {
                    if (fieldServiceOption.ArriveStatusCode != null)
                    {
                        defaultArriveStatus = GetTechnicianStatusFromDB(fieldServiceOption.ArriveStatusCode);
                    }
                    if (fieldServiceOption.DepartStatusCode != null)
                    {
                        defaultDepartStatus = GetTechnicianStatusFromDB(fieldServiceOption.DepartStatusCode);
                    }
                    if (fieldServiceOption.ServiceStartedStatusCode1 != null)
                    {
                        defaultServiceTicketArriveStatus = GetMiscellaneousCodeFromDB("ST", fieldServiceOption.ServiceStartedStatusCode1);
                    }

                    erpOptions = new App_ErpOptions(fieldServiceOption, defaultArriveStatus, defaultDepartStatus, defaultServiceTicketArriveStatus);
                }
            }

            return(erpOptions);
        }
Exemplo n.º 2
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()");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sets the given technician as being clocked-in to a ticket represented by the
        /// specified scheduled appointment object.  The time and status codes provided
        /// will also be used to update the technician data.
        /// </summary>
        /// <param name="technician">Technician to clock in</param>
        /// <param name="scheduledAppointment">Scheduled Appointment object to clock into</param>
        /// <param name="startDateTime">Start date/time</param>
        /// <param name="technicianStatus">Technician status object for the new, clocked-in status</param>
        /// <param name="serviceTicketStatusCode">Work ticket status for the new, clocked-in status</param>
        public void ClockIn(App_Technician technician, App_ScheduledAppointment scheduledAppointment,
                            DateTime startDateTime, JT_TechnicianStatus technicianStatus,
                            JT_MiscellaneousCodes serviceTicketStatusCode)
        {
            // Is this tech already clocked into a ticket?
            if (IsClockedIn(technician))
            {
                throw new Exception("Technician is already clocked into a ticket!");
            }

            int rows = 0;

            // Update the erp record with the ticket info
            JT_Technician erpTech = GetTechnician(technician.TechnicianDeptNo, technician.TechnicianNo);

            erpTech.CurrentStartDate    = startDateTime.Date;
            erpTech.CurrentStartTime    = startDateTime.ToSage100TimeString();
            erpTech.CurrentSalesOrderNo = scheduledAppointment.SalesOrderNumber;
            erpTech.CurrentWTNumber     = scheduledAppointment.WorkTicketNumber;
            erpTech.CurrentWTStep       = scheduledAppointment.WorkTicketStep;
            erpTech.CurrentStatus       = technicianStatus.StatusCode;      // dch rkl 11/03/2016 Save Current Status code to JT_Technician table
            rows = _database.Update(erpTech);

            // create the JT_TransactionImportDetail record
            JT_TransactionImportDetail importDetail = new JT_TransactionImportDetail();

            importDetail.RecordType   = "S";
            importDetail.SalesOrderNo = scheduledAppointment.SalesOrderNumber;
            importDetail.WTNumber     = scheduledAppointment.WorkTicketNumber;
            importDetail.WTStep       = scheduledAppointment.WorkTicketStep;
            importDetail.StatusCode   = serviceTicketStatusCode.MiscellaneousCode;
            //importDetail.statusDate TODO>>> not in table spec!
            importDetail.TransactionDate           = startDateTime.ToShortDateString();
            importDetail.TransactionDateAsDateTime = startDateTime;

            // dch rkl 12/09/2016 per Chris, store start time in start time
            //importDetail.StatusTime = startDateTime.ToSage100TimeString();
            importDetail.StartTime = startDateTime.ToSage100TimeString();

            //importDetail.StatusComment = ""; // not used at this time but might be in the future
            rows = _database.Insert(importDetail);


            // TODO... do we need this anymore now that we are tracking in/out
            //  on technician record?
            JT_DailyTimeEntry newTimeEntry = new JT_DailyTimeEntry();

            newTimeEntry.DepartmentNo    = technician.TechnicianDeptNo;
            newTimeEntry.EmployeeNo      = technician.TechnicianNo;
            newTimeEntry.SalesOrderNo    = scheduledAppointment.SalesOrderNumber;
            newTimeEntry.WTNumber        = scheduledAppointment.WorkTicketNumber;
            newTimeEntry.WTStep          = scheduledAppointment.WorkTicketStep;
            newTimeEntry.StartTime       = startDateTime.ToSage100TimeString();
            newTimeEntry.TransactionDate = startDateTime;
            newTimeEntry.IsModified      = true;

            rows = _database.Insert(newTimeEntry);
        }
        protected async void ButtonClockIn_Clicked(object sender, EventArgs e)
        {
            if (_pickerTechnicianStatus.SelectedIndex < 0)
            {
                //await new MessageBox ("Status", "Select a technician status.", "OK");
                //return;
                MessageBoxResult result = System.Windows.MessageBox.Show("Select a technician status.", "Status", MessageBoxButton.OK);
                if (result == MessageBoxResult.OK)
                {
                    return;
                }
            }
            if (_pickerTicketStatus.SelectedIndex < 0)
            {
                // await DisplayAlert("Status", "Select a ticket status.", "OK");
                // return;
                MessageBoxResult result = System.Windows.MessageBox.Show("Select a ticket status.", "Status", MessageBoxButton.OK);
                if (result == MessageBoxResult.OK)
                {
                    return;
                }
            }

            // dch rkl 11/1/2016 use textbox instead of datetime picker for times BEGIN
            // Validate Arrive Time
            DateTime dtArriveTime;

            if (DateTime.TryParse(_textArriveTime.Text, out dtArriveTime) == false)
            {
                MessageBoxResult result = System.Windows.MessageBox.Show("Enter a valid Arrive Time.", "Arrive Time", MessageBoxButton.OK);
                if (result == MessageBoxResult.OK)
                {
                    return;
                }
            }
            // dch rkl 11/1/2016 use textbox instead of datetime picker for times BEGIN

            JT_TechnicianStatus   selectedTechnicianStatus = _pickerTechnicianStatus.SelectedItem as JT_TechnicianStatus;
            JT_MiscellaneousCodes selectedTicketStatus     = _pickerTicketStatus.SelectedItem as JT_MiscellaneousCodes;

            // dch rkl 11/1/2016 use textbox instead of datetime picker for times
            //TimeSpan timeofday = ((DateTime)_pickerArriveTime.Value).TimeOfDay;
            TimeSpan timeofday = dtArriveTime.TimeOfDay;

            // dch rkl 11/1/2016 use textbox instead of datetime picker for times END

            _vm.ClockIn(timeofday, selectedTechnicianStatus, selectedTicketStatus);
            ContentControl contentArea = (ContentControl)this.Parent;

            _vm.ScheduleDetail.IsCurrent = true;            // dch rkl 01/12/2017 This is what makes the Clock Out Button Appear
            contentArea.Content          = new TicketDetailsPage(_vm.ScheduleDetail);
            //await Navigation.PopToRootAsync();
        }
 public void ClockIn(TimeSpan arriveTime, JT_TechnicianStatus technicianStatus, JT_MiscellaneousCodes serviceTicketStatus)
 {
     // dch rkl 12/07/2016 catch exception
     try
     {
         DateTime clockInTime = DateTime.Today;
         clockInTime = clockInTime.Add(arriveTime);
         App.Database.ClockIn(App.CurrentTechnician, _scheduleDetail, clockInTime, technicianStatus, serviceTicketStatus);
         _scheduleDetail.IsCurrent = true;
     }
     catch (Exception ex)
     {
     }
 }
 public void UpdateTechnicianStatus(JT_TechnicianStatus newStatus)
 {
     // dch rkl 12/07/2016 catch exception
     try
     {
         App.Database.UpdateTechnicianStatus(_technician, newStatus);
     }
     catch (Exception ex)
     {
         // dch rkl 12/07/2016 Log Error
         ErrorReporting errorReporting = new ErrorReporting();
         errorReporting.sendException(ex, "TechDashboard.TechnicianPageViewModel.UpdateTechnicianStatus");
     }
 }
 public void ClockIn(TimeSpan arriveTime, JT_TechnicianStatus technicianStatus, JT_MiscellaneousCodes serviceTicketStatus)
 {
     // dch rkl 12/07/2016 catch exception
     try
     {
         DateTime clockInTime = DateTime.Today;
         clockInTime = clockInTime.Add(arriveTime);
         App.Database.ClockIn(App.CurrentTechnician, _scheduleDetail, clockInTime, technicianStatus, serviceTicketStatus);
         _scheduleDetail.IsCurrent = true;
     }
     catch (Exception ex)
     {
         // dch rkl 12/07/2016 Log Error
         ErrorReporting errorReporting = new ErrorReporting();
         errorReporting.sendException(ex, "TechDashboard.ClockIn");
     }
 }
        protected async void ButtonOK_Clicked(object sender, EventArgs e)
        {
            JT_TechnicianStatus selectedStatus = _pickerTechnicianStatus.SelectedItem as JT_TechnicianStatus;

            if (selectedStatus.StatusCode != _vm.Technician.CurrentStatus)
            {
                // update the status code
                _vm.UpdateTechnicianStatus(selectedStatus);
            }

            if (App.Database.GetCurrentWorkTicket() == null)
            {
                await Navigation.PopAsync();
            }
            else
            {
                await Navigation.PushAsync(new TicketDetailsPage());
            }
        }
Exemplo n.º 9
0
        public async void UpdateTechnicianStatus(App_Technician technician, JT_TechnicianStatus newStatusCode)
        {
            int           rows         = 0;
            JT_Technician techToUpdate = null;

            lock (_locker)
            {
                if (newStatusCode != null)
                {
                    // Get the technician record to update
                    techToUpdate = GetTechnician(technician.TechnicianDeptNo, technician.TechnicianNo);

                    if (techToUpdate != null)
                    {
                        // Set the status and attempt the update
                        techToUpdate.CurrentStatus = newStatusCode.StatusCode;
                        rows = _database.Update(techToUpdate);

                        System.Diagnostics.Debug.WriteLine("Rows updated = " + rows.ToString());

                        if (rows > 0)
                        {
                            // update successful, so set app object, too.
                            technician.CurrentStatus = newStatusCode.StatusCode;
                        }
                    }
                }
            }

            // Now that the DB is updated, send same info back to HQ
            if (techToUpdate != null)
            {
                try {
                    bool result = await UpdateErpTechnicianStatus(techToUpdate);
                }
                catch (Exception exception)
                {
                    // this may fail absent a data connection, could return false
                }
            }
        }
Exemplo n.º 10
0
        protected async void ButtonOK_Clicked(object sender, EventArgs e)
        {
            JT_TechnicianStatus selectedStatus = pkrTechnicianStatus.SelectedItem as JT_TechnicianStatus;

            if (selectedStatus.StatusCode != _vm.Technician.CurrentStatus && App.Database.GetCurrentWorkTicket() != null)
            {
                // update the status code
                _vm.UpdateTechnicianStatus(selectedStatus);
            }

            ContentControl contentArea = (ContentControl)this.Parent;

            if (App.Database.GetCurrentWorkTicket() == null)
            {
                contentArea.Content = new SchedulePage();
            }
            else
            {
                contentArea.Content = new TicketDetailsPage(App.Database.GetScheduledAppointment());
            }
        }
        public ClockInPageViewModel(App_ScheduledAppointment scheduleDetail)
        {
            // dch rkl 12/07/2016 catch exception
            try
            {
                _scheduleDetail          = scheduleDetail;
                _technicianStatusList    = App.Database.GetTechnicianStatusesFromDB();
                _serviceTicketStatusList = App.Database.GetWorkTicketStatusesFromDB();
                _erpOptions = App.Database.GetErpOptions();

                // dch rkl 11/04/2016 Default Arrive Status Code is dependent on JT_FieldServiceOptions or JT_Technician Values BEGIN
                if (_erpOptions.DefaultTechnicianArriveStatusCode != null && _erpOptions.DefaultTechnicianArriveStatusCode.Trim().Length > 0)
                {
                    _defaultArriveStatusCode = _erpOptions.DefaultTechnicianArriveStatusCode;
                }
                else
                {
                    _defaultArriveStatusCode = App.CurrentTechnician.CurrentStatus;
                }
                if (_defaultArriveStatusCode != null && _defaultArriveStatusCode.Trim().Length > 0)
                {
                    JT_TechnicianStatus techStatus = App.Database.GetTechnicianStatusFromDB(_defaultArriveStatusCode);
                    if (techStatus != null && techStatus.StatusDescription != null)
                    {
                        _defaultArriveStatusCodeDescription = techStatus.StatusDescription;
                    }
                }
                else
                {
                    _defaultArriveStatusCodeDescription = "";
                }
                // dch rkl 11/04/2016 Default Arrive Status Code is dependent on JT_FieldServiceOptions or JT_Technician Values END
            }
            catch (Exception ex)
            {
                // dch rkl 12/07/2016 Log Error
                ErrorReporting errorReporting = new ErrorReporting();
                errorReporting.sendException(ex, "TechDashboard.ClockInPageViewModel(App_ScheduledAppointment scheduleDetail)");
            }
        }
        protected async void ButtonClockIn_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;
            }

            JT_TechnicianStatus   selectedTechnicianStatus = _pickerTechnicianStatus.SelectedItem as JT_TechnicianStatus;
            JT_MiscellaneousCodes selectedTicketStatus     = _pickerTicketStatus.SelectedItem as JT_MiscellaneousCodes;



            _vm.ClockIn(_pickerArriveTime.Time, selectedTechnicianStatus, selectedTicketStatus);
            await Navigation.PopToRootAsync();
        }
        public ClockInPageViewModel(App_ScheduledAppointment scheduleDetail)
        {
            // dch rkl 12/07/2016 catch exception
            try
            {
                _scheduleDetail          = scheduleDetail;
                _technicianStatusList    = App.Database.GetTechnicianStatusesFromDB();
                _serviceTicketStatusList = App.Database.GetAllWorkTicketStatusesFromDB().Where(x => x.CodeType == "ST").ToList();
                _erpOptions = App.Database.GetErpOptions();

                // dch rkl 11/04/2016 Default Arrive Status Code is dependent on JT_FieldServiceOptions or JT_Technician Values BEGIN
                if (_erpOptions.DefaultTechnicianArriveStatusCode != null && _erpOptions.DefaultTechnicianArriveStatusCode.Trim().Length > 0)
                {
                    _defaultArriveStatusCode = _erpOptions.DefaultTechnicianArriveStatusCode;
                }
                else
                {
                    _defaultArriveStatusCode = App.CurrentTechnician.CurrentStatus;
                }
                if (_defaultArriveStatusCode != null && _defaultArriveStatusCode.Trim().Length > 0)
                {
                    JT_TechnicianStatus techStatus = App.Database.GetTechnicianStatusFromDB(_defaultArriveStatusCode);
                    if (techStatus != null && techStatus.StatusDescription != null)
                    {
                        _defaultArriveStatusCodeDescription = techStatus.StatusDescription;
                    }
                }
                else
                {
                    _defaultArriveStatusCodeDescription = "";
                }
                // dch rkl 11/04/2016 Default Arrive Status Code is dependent on JT_FieldServiceOptions or JT_Technician Values END
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 14
0
 public void UpdateTechnicianStatus(JT_TechnicianStatus newStatus)
 {
     App.Database.UpdateTechnicianStatus(_technician, newStatus);
 }
Exemplo n.º 15
0
        /// <summary>
        /// Sets the given technician as being clocked-out of a ticket represented by the
        /// specified work ticket object.  The time and status codes provided
        /// will also be used to update the technician data.
        /// dch rkl 01/23/2017 This version of ClockOut includes parameters for when the hours are entered, not the start/stop date and time.
        /// </summary>
        /// <param name="technician">Technician to clock out</param>
        /// <param name="workTicket">Work ticket clocking out of</param>
        /// <param name="stopDateTime">Stop date/time</param>
        /// <param name="technicianStatus">Technician status object for the new, clocked-out status</param>
        /// <param name="serviceTicketStatusCode">Work ticket status for the new, clocked-out status</param>
        /// <param name="activityCode">Activity code to report</param>
        /// <param name="deptWorked">Department in which work was performed</param>
        /// <param name="earningsCode">Earnings code to report</param>
        /// <param name="meterReading">Meter reading (if any) to report</param>
        /// <param name="workPerformedText">Text/notes</param>
        public void ClockOut(App_Technician technician, App_WorkTicket workTicket,
                             JT_TechnicianStatus technicianStatus, JT_MiscellaneousCodes serviceTicketStatusCode,
                             string activityCode, string deptWorked, JT_EarningsCode earningsCode, double hoursBilled, double meterReading,
                             string workPerformedText, double hoursWorked, string svcAgmtContractCode, string billingType)
        {
            int rows = 0;

            lock (_locker)
            {
                // Clear out fields for JT_Technician record
                JT_Technician erpTech = GetTechnician(technician.TechnicianDeptNo, technician.TechnicianNo);

                // update time entry first
                DateTime          dtStartTime      = DateTime.Now;
                JT_DailyTimeEntry currentTimeEntry = GetClockedInTimeEntry(technician);
                if (currentTimeEntry != null)
                {
                    if (DateTime.TryParse(currentTimeEntry.StartTime, out dtStartTime))
                    {
                        DateTime dtStopTime = dtStartTime.AddHours(hoursWorked);
                        currentTimeEntry.EndTime = dtStopTime.ToSage100TimeString();
                        _database.Update(currentTimeEntry);
                    }
                }

                erpTech.CurrentStartDate    = new DateTime();
                erpTech.CurrentStartTime    = null;
                erpTech.CurrentSalesOrderNo = null;
                erpTech.CurrentWTNumber     = null;
                erpTech.CurrentWTStep       = null;
                erpTech.CurrentStatus       = technicianStatus.StatusCode;      // dch rkl 11/03/2016 Save Current Status code to JT_Technician table
                rows = _database.Update(erpTech);

                // insert the JT_TransactionImportDetail record
                JT_TransactionImportDetail importDetail = new JT_TransactionImportDetail();
                importDetail.RecordType   = "S";
                importDetail.SalesOrderNo = workTicket.SalesOrderNo;
                importDetail.WTNumber     = workTicket.WTNumber;
                importDetail.WTStep       = workTicket.WTStep;
                importDetail.StatusCode   = serviceTicketStatusCode.MiscellaneousCode;

                importDetail.TransactionDate           = dtStartTime.ToSage100DateString();
                importDetail.TransactionDateAsDateTime = dtStartTime;
                importDetail.HoursWorked = hoursWorked;
                rows = _database.Insert(importDetail);

                // insert another JT_TransactionImportDetail record to record the labor
                importDetail                           = new JT_TransactionImportDetail();
                importDetail.RecordType                = "L";
                importDetail.SalesOrderNo              = workTicket.SalesOrderNo;
                importDetail.WTNumber                  = workTicket.WTNumber;
                importDetail.WTStep                    = workTicket.WTStep;
                importDetail.EmployeeDeptNo            = technician.TechnicianDeptNo;
                importDetail.EmployeeNo                = technician.TechnicianNo;
                importDetail.ActivityCode              = activityCode;
                importDetail.DeptWorkedIn              = deptWorked;
                importDetail.EarningsCode              = earningsCode.EarningsCode;
                importDetail.TransactionDate           = dtStartTime.ToSage100DateString();
                importDetail.TransactionDateAsDateTime = dtStartTime;
                importDetail.HoursWorked               = hoursWorked;
                //bk add hours billed
                importDetail.BillableHours       = hoursBilled;
                importDetail.BillingType         = billingType;
                importDetail.MeterReading        = meterReading;
                importDetail.WorkPerformed       = workPerformedText;
                importDetail.SvcAgmtContractCode = svcAgmtContractCode;             // dch rkl 01/23/2017 Include Service Agreement Code
                rows = _database.Insert(importDetail);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Sets the given technician as being clocked-out of a ticket represented by the
        /// specified work ticket object.  The time and status codes provided
        /// will also be used to update the technician data.
        /// </summary>
        /// <param name="technician">Technician to clock out</param>
        /// <param name="workTicket">Work ticket clocking out of</param>
        /// <param name="stopDateTime">Stop date/time</param>
        /// <param name="technicianStatus">Technician status object for the new, clocked-out status</param>
        /// <param name="serviceTicketStatusCode">Work ticket status for the new, clocked-out status</param>
        /// <param name="activityCode">Activity code to report</param>
        /// <param name="deptWorked">Department in which work was performed</param>
        /// <param name="earningsCode">Earnings code to report</param>
        /// <param name="meterReading">Meter reading (if any) to report</param>
        /// <param name="workPerformedText">Text/notes</param>
        public void ClockOut(App_Technician technician, App_WorkTicket workTicket,
                             DateTime stopDateTime, JT_TechnicianStatus technicianStatus, JT_MiscellaneousCodes serviceTicketStatusCode,
                             string activityCode, string deptWorked, JT_EarningsCode earningsCode, double hoursBilled, double hoursWorked, double meterReading,
                             string workPerformedText, string svcAgmtContractCode, string clockoutDate, string billingType)
        {
            int      rows = 0;
            DateTime startDateTime;

            lock (_locker)
            {
                // Clear out fields for JT_Technician record
                JT_Technician erpTech = GetTechnician(technician.TechnicianDeptNo, technician.TechnicianNo);

                // Record starting date/time in local variable
                startDateTime = erpTech.CurrentStartDate; // Add time
                startDateTime = startDateTime.Add(erpTech.CurrentStartTime.ToSage100TimeSpan());

                if (hoursBilled <= 0)
                {
                    hoursBilled = (stopDateTime - startDateTime).TotalHours;
                }

                // update time entry first
                JT_DailyTimeEntry currentTimeEntry = GetClockedInTimeEntry(technician);
                if (currentTimeEntry != null)
                {
                    currentTimeEntry.EndTime = stopDateTime.ToSage100TimeString();
                    _database.Update(currentTimeEntry);
                }

                erpTech.CurrentStartDate    = new DateTime();
                erpTech.CurrentStartTime    = null;
                erpTech.CurrentSalesOrderNo = null;
                erpTech.CurrentWTNumber     = null;
                erpTech.CurrentWTStep       = null;
                erpTech.CurrentStatus       = technicianStatus.StatusCode;      // dch rkl 11/03/2016 Save Current Status code to JT_Technician table
                rows = _database.Update(erpTech);

                rows = _database.Update(erpTech);


                // insert the JT_TransactionImportDetail record
                JT_TransactionImportDetail importDetail = new JT_TransactionImportDetail();
                importDetail.RecordType   = "S";
                importDetail.SalesOrderNo = workTicket.SalesOrderNo;
                importDetail.WTNumber     = workTicket.WTNumber;
                importDetail.WTStep       = workTicket.WTStep;
                importDetail.StatusCode   = serviceTicketStatusCode.MiscellaneousCode;
                //importDetail.statusDate TODO>>> not in table spec!

                // dch rkl 12/09/2016 per Chris, store start time in start time
                //importDetail.StatusTime = stopDateTime.ToSage100TimeString();
                importDetail.StartTime = stopDateTime.ToSage100TimeString();

                importDetail.TransactionDate           = stopDateTime.ToSage100DateString();
                importDetail.TransactionDateAsDateTime = stopDateTime;
                //importDetail.StatusComment = "TODO"; // not used at this time but might be in the future
                rows = _database.Insert(importDetail);

                // insert another JT_TransactionImportDetail record to record the labor
                importDetail                     = new JT_TransactionImportDetail();
                importDetail.RecordType          = "L";
                importDetail.SalesOrderNo        = workTicket.SalesOrderNo;
                importDetail.WTNumber            = workTicket.WTNumber;
                importDetail.WTStep              = workTicket.WTStep;
                importDetail.EmployeeDeptNo      = technician.TechnicianDeptNo;
                importDetail.EmployeeNo          = technician.TechnicianNo;
                importDetail.ActivityCode        = activityCode;
                importDetail.DeptWorkedIn        = deptWorked;
                importDetail.EarningsCode        = earningsCode.EarningsCode;
                importDetail.SvcAgmtContractCode = svcAgmtContractCode;
                //importDetail.TransactionDate = stopDateTime.ToSage100DateString();

                // dch rkl 02/03/2017 Use Start Date as Tran Date
                DateTime dtTranDt;
                if (DateTime.TryParse(clockoutDate, out dtTranDt))
                {
                    importDetail.TransactionDate           = dtTranDt.ToSage100DateString();
                    importDetail.TransactionDateAsDateTime = dtTranDt;
                }
                else
                {
                    importDetail.TransactionDate           = startDateTime.ToSage100DateString();
                    importDetail.TransactionDateAsDateTime = startDateTime;
                }
                //importDetail.TransactionDate = startDateTime.ToSage100DateString();
                //importDetail.TransactionDateAsDateTime = startDateTime;
                importDetail.StartTime   = startDateTime.ToSage100TimeString();
                importDetail.EndTime     = stopDateTime.ToSage100TimeString();
                importDetail.HoursWorked = hoursWorked; // (stopDateTime - startDateTime).TotalHours;
                //bk adding hours billed and billing type
                importDetail.BillableHours       = hoursBilled;
                importDetail.BillingType         = billingType;
                importDetail.MeterReading        = meterReading;
                importDetail.WorkPerformed       = workPerformedText;
                importDetail.SvcAgmtContractCode = svcAgmtContractCode;             // dch rkl 01/23/2017 Include Service Agreement Code
                rows = _database.Insert(importDetail);
            }
        }
        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();
        }
        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();
        }