updard Adoptions in andriod for new backend
This commit is contained in:
@@ -46,6 +46,7 @@ public class AdoptionAdapter extends RecyclerView.Adapter<AdoptionAdapter.Adopti
|
|||||||
|
|
||||||
binding.tvAdoptionCustomerName.setText(a.getCustomerName() != null ? a.getCustomerName() : "");
|
binding.tvAdoptionCustomerName.setText(a.getCustomerName() != null ? a.getCustomerName() : "");
|
||||||
binding.tvAdoptionPetName.setText("Pet: " + (a.getPetName() != null ? a.getPetName() : ""));
|
binding.tvAdoptionPetName.setText("Pet: " + (a.getPetName() != null ? a.getPetName() : ""));
|
||||||
|
binding.tvAdoptionStaffName.setText("Staff: " + (a.getEmployeeName() != null ? a.getEmployeeName() : "N/A"));
|
||||||
binding.tvAdoptionDate.setText("Date: " + (a.getAdoptionDate() != null ? a.getAdoptionDate() : ""));
|
binding.tvAdoptionDate.setText("Date: " + (a.getAdoptionDate() != null ? a.getAdoptionDate() : ""));
|
||||||
binding.tvAdoptionFee.setText(a.getAdoptionFee() != null ? "$" + a.getAdoptionFee() : "");
|
binding.tvAdoptionFee.setText(a.getAdoptionFee() != null ? "$" + a.getAdoptionFee() : "");
|
||||||
|
|
||||||
|
|||||||
@@ -18,80 +18,127 @@ public class AdoptionDTO {
|
|||||||
private String createdAt;
|
private String createdAt;
|
||||||
private String updatedAt;
|
private String updatedAt;
|
||||||
|
|
||||||
public AdoptionDTO(Long petId, Long customerId, Long sourceStoreId, String adoptionDate, String adoptionStatus) {
|
public AdoptionDTO() {}
|
||||||
this.petId = petId;
|
|
||||||
this.customerId = customerId;
|
|
||||||
this.sourceStoreId = sourceStoreId;
|
|
||||||
this.adoptionDate = adoptionDate;
|
|
||||||
this.adoptionStatus = adoptionStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AdoptionDTO(Long petId, Long customerId, Long employeeId, Long sourceStoreId, String adoptionDate, String adoptionStatus) {
|
public AdoptionDTO(Long petId, Long customerId, Long employeeId, Long sourceStoreId, String adoptionDate, String adoptionStatus, BigDecimal adoptionFee) {
|
||||||
this.petId = petId;
|
this.petId = petId;
|
||||||
this.customerId = customerId;
|
this.customerId = customerId;
|
||||||
this.employeeId = employeeId;
|
this.employeeId = employeeId;
|
||||||
this.sourceStoreId = sourceStoreId;
|
this.sourceStoreId = sourceStoreId;
|
||||||
this.adoptionDate = adoptionDate;
|
this.adoptionDate = adoptionDate;
|
||||||
this.adoptionStatus = adoptionStatus;
|
this.adoptionStatus = adoptionStatus;
|
||||||
|
this.adoptionFee = adoptionFee;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getAdoptionId() {
|
public Long getAdoptionId() {
|
||||||
return adoptionId;
|
return adoptionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAdoptionId(Long adoptionId) {
|
||||||
|
this.adoptionId = adoptionId;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getPetId() {
|
public Long getPetId() {
|
||||||
return petId;
|
return petId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPetId(Long petId) {
|
||||||
|
this.petId = petId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getPetName() {
|
public String getPetName() {
|
||||||
return petName;
|
return petName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setPetName(String petName) {
|
||||||
|
this.petName = petName;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getCustomerId() {
|
public Long getCustomerId() {
|
||||||
return customerId;
|
return customerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCustomerId(Long customerId) {
|
||||||
|
this.customerId = customerId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getCustomerName() {
|
public String getCustomerName() {
|
||||||
return customerName;
|
return customerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCustomerName(String customerName) {
|
||||||
|
this.customerName = customerName;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getEmployeeId() {
|
public Long getEmployeeId() {
|
||||||
return employeeId;
|
return employeeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEmployeeId(Long employeeId) {
|
||||||
|
this.employeeId = employeeId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getEmployeeName() {
|
public String getEmployeeName() {
|
||||||
return employeeName;
|
return employeeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEmployeeName(String employeeName) {
|
||||||
|
this.employeeName = employeeName;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getSourceStoreId() {
|
public Long getSourceStoreId() {
|
||||||
return sourceStoreId;
|
return sourceStoreId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSourceStoreId(Long sourceStoreId) {
|
||||||
|
this.sourceStoreId = sourceStoreId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSourceStoreName() {
|
public String getSourceStoreName() {
|
||||||
return sourceStoreName;
|
return sourceStoreName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSourceStoreName(String sourceStoreName) {
|
||||||
|
this.sourceStoreName = sourceStoreName;
|
||||||
|
}
|
||||||
|
|
||||||
public String getAdoptionDate() {
|
public String getAdoptionDate() {
|
||||||
return adoptionDate;
|
return adoptionDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAdoptionDate(String adoptionDate) {
|
||||||
|
this.adoptionDate = adoptionDate;
|
||||||
|
}
|
||||||
|
|
||||||
public String getAdoptionStatus() {
|
public String getAdoptionStatus() {
|
||||||
return adoptionStatus;
|
return adoptionStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStatus() {
|
public void setAdoptionStatus(String adoptionStatus) {
|
||||||
return adoptionStatus;
|
this.adoptionStatus = adoptionStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigDecimal getAdoptionFee() {
|
public BigDecimal getAdoptionFee() {
|
||||||
return adoptionFee;
|
return adoptionFee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAdoptionFee(BigDecimal adoptionFee) {
|
||||||
|
this.adoptionFee = adoptionFee;
|
||||||
|
}
|
||||||
|
|
||||||
public String getCreatedAt() {
|
public String getCreatedAt() {
|
||||||
return createdAt;
|
return createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCreatedAt(String createdAt) {
|
||||||
|
this.createdAt = createdAt;
|
||||||
|
}
|
||||||
|
|
||||||
public String getUpdatedAt() {
|
public String getUpdatedAt() {
|
||||||
return updatedAt;
|
return updatedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUpdatedAt(String updatedAt) {
|
||||||
|
this.updatedAt = updatedAt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ import com.example.petstoremobile.viewmodels.AdoptionViewModel;
|
|||||||
import com.example.petstoremobile.viewmodels.CustomerViewModel;
|
import com.example.petstoremobile.viewmodels.CustomerViewModel;
|
||||||
import com.example.petstoremobile.viewmodels.PetViewModel;
|
import com.example.petstoremobile.viewmodels.PetViewModel;
|
||||||
import com.example.petstoremobile.viewmodels.StoreViewModel;
|
import com.example.petstoremobile.viewmodels.StoreViewModel;
|
||||||
|
import com.example.petstoremobile.viewmodels.UserViewModel;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint;
|
import dagger.hilt.android.AndroidEntryPoint;
|
||||||
@@ -37,10 +39,12 @@ public class AdoptionDetailFragment extends Fragment {
|
|||||||
private long preselectedPetId = -1;
|
private long preselectedPetId = -1;
|
||||||
private long preselectedCustomerId = -1;
|
private long preselectedCustomerId = -1;
|
||||||
private long preselectedStoreId = -1;
|
private long preselectedStoreId = -1;
|
||||||
|
private long preselectedEmployeeId = -1;
|
||||||
|
|
||||||
private List<PetDTO> petList = new ArrayList<>();
|
private List<PetDTO> petList = new ArrayList<>();
|
||||||
private List<CustomerDTO> customerList = new ArrayList<>();
|
private List<CustomerDTO> customerList = new ArrayList<>();
|
||||||
private List<StoreDTO> storeList = new ArrayList<>();
|
private List<StoreDTO> storeList = new ArrayList<>();
|
||||||
|
private List<UserDTO> employeeList = new ArrayList<>();
|
||||||
|
|
||||||
private final String[] STATUSES = {"Pending", "Completed", "Cancelled"};
|
private final String[] STATUSES = {"Pending", "Completed", "Cancelled"};
|
||||||
|
|
||||||
@@ -48,6 +52,7 @@ public class AdoptionDetailFragment extends Fragment {
|
|||||||
private PetViewModel petViewModel;
|
private PetViewModel petViewModel;
|
||||||
private CustomerViewModel customerViewModel;
|
private CustomerViewModel customerViewModel;
|
||||||
private StoreViewModel storeViewModel;
|
private StoreViewModel storeViewModel;
|
||||||
|
private UserViewModel userViewModel;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -56,6 +61,7 @@ public class AdoptionDetailFragment extends Fragment {
|
|||||||
petViewModel = new ViewModelProvider(this).get(PetViewModel.class);
|
petViewModel = new ViewModelProvider(this).get(PetViewModel.class);
|
||||||
customerViewModel = new ViewModelProvider(this).get(CustomerViewModel.class);
|
customerViewModel = new ViewModelProvider(this).get(CustomerViewModel.class);
|
||||||
storeViewModel = new ViewModelProvider(this).get(StoreViewModel.class);
|
storeViewModel = new ViewModelProvider(this).get(StoreViewModel.class);
|
||||||
|
userViewModel = new ViewModelProvider(this).get(UserViewModel.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -113,6 +119,7 @@ public class AdoptionDetailFragment extends Fragment {
|
|||||||
loadPets();
|
loadPets();
|
||||||
loadCustomers();
|
loadCustomers();
|
||||||
loadStores();
|
loadStores();
|
||||||
|
loadEmployees();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -179,6 +186,27 @@ public class AdoptionDetailFragment extends Fragment {
|
|||||||
preselectedStoreId, StoreDTO::getStoreId);
|
preselectedStoreId, StoreDTO::getStoreId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the list of employees from the API.
|
||||||
|
*/
|
||||||
|
private void loadEmployees() {
|
||||||
|
userViewModel.getUsers("STAFF", 0, 100).observe(getViewLifecycleOwner(), resource -> {
|
||||||
|
if (resource.status == Resource.Status.SUCCESS && resource.data != null) {
|
||||||
|
employeeList = resource.data.getContent();
|
||||||
|
refreshEmployeeSpinner();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populates the employee selection spinner with data.
|
||||||
|
*/
|
||||||
|
private void refreshEmployeeSpinner() {
|
||||||
|
SpinnerUtils.populateSpinner(requireContext(), binding.spinnerAdoptionEmployee, employeeList,
|
||||||
|
UserDTO::getFullName, "-- Select Staff --",
|
||||||
|
preselectedEmployeeId, UserDTO::getId);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles arguments to determine if the fragment is in edit or add mode.
|
* Handles arguments to determine if the fragment is in edit or add mode.
|
||||||
*/
|
*/
|
||||||
@@ -210,12 +238,16 @@ public class AdoptionDetailFragment extends Fragment {
|
|||||||
preselectedPetId = a.getPetId() != null ? a.getPetId() : -1;
|
preselectedPetId = a.getPetId() != null ? a.getPetId() : -1;
|
||||||
preselectedCustomerId = a.getCustomerId() != null ? a.getCustomerId() : -1;
|
preselectedCustomerId = a.getCustomerId() != null ? a.getCustomerId() : -1;
|
||||||
preselectedStoreId = a.getSourceStoreId() != null ? a.getSourceStoreId() : -1;
|
preselectedStoreId = a.getSourceStoreId() != null ? a.getSourceStoreId() : -1;
|
||||||
|
preselectedEmployeeId = a.getEmployeeId() != null ? a.getEmployeeId() : -1;
|
||||||
|
|
||||||
binding.etAdoptionDate.setText(a.getAdoptionDate());
|
binding.etAdoptionDate.setText(a.getAdoptionDate());
|
||||||
|
binding.etAdoptionFee.setText(a.getAdoptionFee() != null ? a.getAdoptionFee().toString() : "");
|
||||||
SpinnerUtils.setSelectionByValue(binding.spinnerAdoptionStatus, a.getAdoptionStatus());
|
SpinnerUtils.setSelectionByValue(binding.spinnerAdoptionStatus, a.getAdoptionStatus());
|
||||||
|
|
||||||
refreshPetSpinner();
|
refreshPetSpinner();
|
||||||
refreshCustomerSpinner();
|
refreshCustomerSpinner();
|
||||||
refreshStoreSpinner();
|
refreshStoreSpinner();
|
||||||
|
refreshEmployeeSpinner();
|
||||||
} else if (resource.status == Resource.Status.ERROR) {
|
} else if (resource.status == Resource.Status.ERROR) {
|
||||||
Toast.makeText(getContext(), "Failed to load adoption: " + resource.message, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), "Failed to load adoption: " + resource.message, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
@@ -240,17 +272,36 @@ public class AdoptionDetailFragment extends Fragment {
|
|||||||
Toast.makeText(getContext(), "Select a date", Toast.LENGTH_SHORT).show(); return;
|
Toast.makeText(getContext(), "Select a date", Toast.LENGTH_SHORT).show(); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BigDecimal fee = BigDecimal.ZERO;
|
||||||
|
String feeStr = binding.etAdoptionFee.getText().toString().trim();
|
||||||
|
if (!feeStr.isEmpty()) {
|
||||||
|
try {
|
||||||
|
fee = new BigDecimal(feeStr);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
Toast.makeText(getContext(), "Invalid fee format", Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CustomerDTO customer = customerList.get(binding.spinnerAdoptionCustomer.getSelectedItemPosition() - 1);
|
CustomerDTO customer = customerList.get(binding.spinnerAdoptionCustomer.getSelectedItemPosition() - 1);
|
||||||
PetDTO pet = petList.get(binding.spinnerAdoptionPet.getSelectedItemPosition() - 1);
|
PetDTO pet = petList.get(binding.spinnerAdoptionPet.getSelectedItemPosition() - 1);
|
||||||
StoreDTO store = storeList.get(binding.spinnerAdoptionStore.getSelectedItemPosition() - 1);
|
StoreDTO store = storeList.get(binding.spinnerAdoptionStore.getSelectedItemPosition() - 1);
|
||||||
|
|
||||||
|
Long employeeId = null;
|
||||||
|
if (binding.spinnerAdoptionEmployee.getSelectedItemPosition() > 0) {
|
||||||
|
employeeId = employeeList.get(binding.spinnerAdoptionEmployee.getSelectedItemPosition() - 1).getId();
|
||||||
|
}
|
||||||
|
|
||||||
String status = STATUSES[binding.spinnerAdoptionStatus.getSelectedItemPosition()];
|
String status = STATUSES[binding.spinnerAdoptionStatus.getSelectedItemPosition()];
|
||||||
|
|
||||||
AdoptionDTO dto = new AdoptionDTO(
|
AdoptionDTO dto = new AdoptionDTO(
|
||||||
pet.getPetId(),
|
pet.getPetId(),
|
||||||
customer.getCustomerId(),
|
customer.getCustomerId(),
|
||||||
|
employeeId,
|
||||||
store.getStoreId(),
|
store.getStoreId(),
|
||||||
date,
|
date,
|
||||||
status
|
status,
|
||||||
|
fee
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
|
|||||||
@@ -95,6 +95,21 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="16dp"/>
|
android:layout_marginBottom="16dp"/>
|
||||||
|
|
||||||
|
<!-- Employee -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Handled By (Staff)"
|
||||||
|
android:textColor="@color/text_dark"
|
||||||
|
android:textSize="12sp"
|
||||||
|
android:layout_marginBottom="4dp"/>
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/spinnerAdoptionEmployee"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="16dp"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -129,6 +144,23 @@
|
|||||||
android:drawableEnd="@android:drawable/ic_menu_my_calendar"
|
android:drawableEnd="@android:drawable/ic_menu_my_calendar"
|
||||||
android:layout_marginBottom="16dp"/>
|
android:layout_marginBottom="16dp"/>
|
||||||
|
|
||||||
|
<!-- Adoption Fee -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Adoption Fee"
|
||||||
|
android:textColor="@color/text_dark"
|
||||||
|
android:textSize="12sp"
|
||||||
|
android:layout_marginBottom="4dp"/>
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/etAdoptionFee"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="0.00"
|
||||||
|
android:inputType="numberDecimal"
|
||||||
|
android:layout_marginBottom="16dp"/>
|
||||||
|
|
||||||
<!-- Status -->
|
<!-- Status -->
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
@@ -53,6 +53,18 @@
|
|||||||
android:textColor="#888888"
|
android:textColor="#888888"
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvAdoptionStaffName"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="2dp"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:text="Staff: "
|
||||||
|
android:textColor="#888888"
|
||||||
|
android:textSize="13sp"
|
||||||
|
android:textStyle="italic" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|||||||
Reference in New Issue
Block a user