updated backend so booked appointment automatically changes to completed
This commit is contained in:
@@ -37,6 +37,7 @@ public class AppointmentDetailFragment extends Fragment {
|
||||
|
||||
private long appointmentId = -1;
|
||||
private boolean isEditing = false;
|
||||
private boolean isPastAppointment = false;
|
||||
private long preselectedPetId = -1;
|
||||
private long preselectedServiceId = -1;
|
||||
private long preselectedCustomerId = -1;
|
||||
@@ -161,6 +162,7 @@ public class AppointmentDetailFragment extends Fragment {
|
||||
*/
|
||||
private void setupDatePicker() {
|
||||
binding.etAppointmentDate.setOnClickListener(v -> {
|
||||
if (isPastAppointment) return;
|
||||
Calendar c = Calendar.getInstance();
|
||||
DatePickerDialog d = new DatePickerDialog(requireContext(),
|
||||
(dp,y,m,d1) -> binding.etAppointmentDate.setText(
|
||||
@@ -376,6 +378,8 @@ public class AppointmentDetailFragment extends Fragment {
|
||||
SpinnerUtils.setSelectionByValue(binding.spinnerAppointmentStatus, formattedStatus);
|
||||
}
|
||||
|
||||
checkIfPastAndDisable(a.getAppointmentDate(), time);
|
||||
|
||||
refreshPetSpinner();
|
||||
refreshServiceSpinner();
|
||||
refreshCustomerSpinner();
|
||||
@@ -387,6 +391,92 @@ public class AppointmentDetailFragment extends Fragment {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the appointment is in the past and disables fields.
|
||||
*/
|
||||
private void checkIfPastAndDisable(String date, String time) {
|
||||
if (date == null || time == null) return;
|
||||
try {
|
||||
Calendar selected = Calendar.getInstance();
|
||||
String[] dateParts = date.split("-");
|
||||
String[] timeParts = time.split(":");
|
||||
selected.set(
|
||||
Integer.parseInt(dateParts[0]),
|
||||
Integer.parseInt(dateParts[1]) - 1,
|
||||
Integer.parseInt(dateParts[2]),
|
||||
Integer.parseInt(timeParts[0]),
|
||||
Integer.parseInt(timeParts[1]),
|
||||
0
|
||||
);
|
||||
|
||||
Object selectedItem = binding.spinnerAppointmentStatus.getSelectedItem();
|
||||
String currentStatus = selectedItem != null ? selectedItem.toString() : "";
|
||||
|
||||
// If the appointment is already Cancelled, disable all fields
|
||||
if ("Cancelled".equalsIgnoreCase(currentStatus)) {
|
||||
isPastAppointment = true;
|
||||
disableAllExceptStatus();
|
||||
binding.spinnerAppointmentStatus.setEnabled(false);
|
||||
binding.spinnerAppointmentStatus.setAlpha(0.5f);
|
||||
binding.btnSaveAppointment.setVisibility(View.GONE);
|
||||
return;
|
||||
}
|
||||
|
||||
// If the appointment date/time is in the past
|
||||
if (selected.before(Calendar.getInstance())) {
|
||||
isPastAppointment = true;
|
||||
disableAllExceptStatus();
|
||||
|
||||
// Make status spinner only have Completed or Missed
|
||||
SpinnerUtils.setupStringSpinner(requireContext(), binding.spinnerAppointmentStatus,
|
||||
new String[]{"Completed", "Missed"});
|
||||
|
||||
// Restore selection if it's already one of the valid options
|
||||
if (currentStatus.equals("Completed") || currentStatus.equals("Missed")) {
|
||||
SpinnerUtils.setSelectionByValue(binding.spinnerAppointmentStatus, currentStatus);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("APPT_DETAIL", "Error parsing date/time for past check: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables all input fields except the status spinner
|
||||
*/
|
||||
private void disableAllExceptStatus() {
|
||||
binding.spinnerCustomer.setEnabled(false);
|
||||
binding.spinnerStore.setEnabled(false);
|
||||
binding.spinnerPet.setEnabled(false);
|
||||
binding.spinnerService.setEnabled(false);
|
||||
binding.spinnerStaff.setEnabled(false);
|
||||
binding.etAppointmentDate.setEnabled(false);
|
||||
binding.spinnerHour.setEnabled(false);
|
||||
binding.spinnerMinute.setEnabled(false);
|
||||
|
||||
float disabledAlpha = 0.5f;
|
||||
binding.spinnerCustomer.setAlpha(disabledAlpha);
|
||||
binding.spinnerStore.setAlpha(disabledAlpha);
|
||||
binding.spinnerPet.setAlpha(disabledAlpha);
|
||||
binding.spinnerService.setAlpha(disabledAlpha);
|
||||
binding.spinnerStaff.setAlpha(disabledAlpha);
|
||||
binding.etAppointmentDate.setAlpha(disabledAlpha);
|
||||
binding.spinnerHour.setAlpha(disabledAlpha);
|
||||
binding.spinnerMinute.setAlpha(disabledAlpha);
|
||||
|
||||
binding.tvLabelCustomer.setAlpha(disabledAlpha);
|
||||
binding.tvLabelStore.setAlpha(disabledAlpha);
|
||||
binding.tvLabelPet.setAlpha(disabledAlpha);
|
||||
binding.tvLabelService.setAlpha(disabledAlpha);
|
||||
binding.tvLabelStaff.setAlpha(disabledAlpha);
|
||||
binding.tvLabelDate.setAlpha(disabledAlpha);
|
||||
binding.tvLabelTime.setAlpha(disabledAlpha);
|
||||
|
||||
// Keep status enabled
|
||||
binding.spinnerAppointmentStatus.setEnabled(true);
|
||||
binding.spinnerAppointmentStatus.setAlpha(1.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates input and saves the appointment to the backend.
|
||||
*/
|
||||
|
||||
@@ -136,6 +136,7 @@
|
||||
|
||||
<!-- Staff -->
|
||||
<TextView
|
||||
android:id="@+id/tvLabelStaff"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Staff"
|
||||
@@ -152,6 +153,7 @@
|
||||
<!-- Appointment Date -->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvLabelDate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Appointment Date"
|
||||
@@ -172,6 +174,7 @@
|
||||
|
||||
<!-- Appointment Time-->
|
||||
<TextView
|
||||
android:id="@+id/tvLabelTime"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Appointment Time"
|
||||
|
||||
Reference in New Issue
Block a user