diff --git a/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/navigation/CollectionSheetNavigation.kt b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/navigation/CollectionSheetNavigation.kt index 7bb7a09889f..d804a5a53ec 100644 --- a/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/navigation/CollectionSheetNavigation.kt +++ b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/navigation/CollectionSheetNavigation.kt @@ -6,14 +6,18 @@ import androidx.navigation.NavType import androidx.navigation.compose.composable import androidx.navigation.navArgument import androidx.navigation.navigation +import com.google.gson.Gson import com.mifos.core.common.utils.Constants import com.mifos.core.network.model.IndividualCollectionSheetPayload import com.mifos.core.objects.accounts.loan.PaymentTypeOptions import com.mifos.core.objects.collectionsheet.IndividualCollectionSheet import com.mifos.core.objects.collectionsheet.LoanAndClientName +import com.mifos.core.objects.collectionsheet.LoanCollectionSheet import com.mifos.feature.individual_collection_sheet.generate_collection_sheet.GenerateCollectionSheetScreen import com.mifos.feature.individual_collection_sheet.individual_collection_sheet.ui.IndividualCollectionSheetScreen import com.mifos.feature.individual_collection_sheet.individual_collection_sheet_details.IndividualCollectionSheetDetailsScreen +import com.mifos.feature.individual_collection_sheet.payment_details.PaymentDetailsScreenContent +import com.mifos.feature.individual_collection_sheet.payment_details.PaymentDetailsScreenRoute /** * Created by Pronay Sarker on 20/08/2024 (4:06 PM) @@ -21,7 +25,6 @@ import com.mifos.feature.individual_collection_sheet.individual_collection_sheet fun NavGraphBuilder.individualCollectionSheetNavGraph( navController: NavController, onBackPressed: () -> Unit, - navigateToPaymentDetails: (Int, IndividualCollectionSheetPayload, List, LoanAndClientName, List, Int) -> Unit ) { navigation( route = "generate_collection_sheet", @@ -29,13 +32,18 @@ fun NavGraphBuilder.individualCollectionSheetNavGraph( ) { individualCollectionSheetScreen( onBackPressed = onBackPressed, - onDetail = { _, sheet -> navController.navigateToIndividualCollectionSheetDetailScreen(sheet) } + onDetail = { _, sheet -> + navController.navigateToIndividualCollectionSheetDetailScreen(sheet) + } + ) individualCollectionSheetDetailScreen( onBackPressed = onBackPressed, - submit = navigateToPaymentDetails + submit = navController::navigateToPaymentDetailsScreen ) + + paymentDetailsScreen() } } @@ -80,10 +88,47 @@ fun NavGraphBuilder.generateCollectionSheetScreen( } } +fun NavGraphBuilder.paymentDetailsScreen() { + composable( + route = CollectionSheetScreens.PaymentDetailsScreen.route, + arguments = listOf( + navArgument(name = Constants.ADAPTER_POSITION, builder = { NavType.IntType }), + navArgument(name = Constants.CLIENT_ID, builder = { NavType.IntType }), + navArgument(name = Constants.PAYLOAD, builder = { NavType.StringType }), + navArgument(name = Constants.PAYMENT_LIST, builder = { NavType.StringType }), + navArgument(name = Constants.LOAN_AND_CLIENT, builder = { NavType.StringType }), + navArgument(name = Constants.PAYMENT_OPTIONS, builder = { NavType.StringType }), + ) + ) { + PaymentDetailsScreenRoute() + } +} + fun NavController.navigateToIndividualCollectionSheetDetailScreen(sheet: IndividualCollectionSheet) { navigate(CollectionSheetScreens.IndividualCollectionSheetDetailScreen.argument(sheet)) } -fun NavController.navigateToIndividualCollectionSheet() { - navigate(CollectionSheetScreens.IndividualCollectionSheetScreen.route) -} \ No newline at end of file +fun NavController.navigateToPaymentDetailsScreen( + position: Int, + payload: IndividualCollectionSheetPayload, + paymentTypeOptionsName: List, + loansAndClientName: LoanAndClientName, + paymentTypeOptions: List, + clientId: Int +) { + val payloadInGsonString = Gson().toJson(payload) + val paymentTypeOptionNameInGsonString = Gson().toJson(paymentTypeOptionsName) + val loansAndClientNameInGsonString = Gson().toJson(loansAndClientName) + val paymentTypeOptionsInGsonString = Gson().toJson(paymentTypeOptions) + + navigate( + CollectionSheetScreens.PaymentDetailsScreen.argument( + position, + payloadInGsonString, + paymentTypeOptionNameInGsonString, + loansAndClientNameInGsonString, + paymentTypeOptionsInGsonString, + clientId + ) + ) +} diff --git a/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/navigation/CollectionSheetScreens.kt b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/navigation/CollectionSheetScreens.kt index 209a63136e4..b2da6e0fa6d 100644 --- a/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/navigation/CollectionSheetScreens.kt +++ b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/navigation/CollectionSheetScreens.kt @@ -2,7 +2,9 @@ package com.mifos.feature.individual_collection_sheet.navigation import com.google.gson.Gson import com.mifos.core.common.utils.Constants +import com.mifos.core.objects.accounts.loan.PaymentTypeOptions import com.mifos.core.objects.collectionsheet.IndividualCollectionSheet +import com.mifos.core.objects.collectionsheet.LoanAndClientName import com.mifos.core.objects.db.CollectionSheet import com.mifos.feature.individual_collection_sheet.generate_collection_sheet.GenerateCollectionSheetUiState @@ -11,11 +13,28 @@ import com.mifos.feature.individual_collection_sheet.generate_collection_sheet.G */ sealed class CollectionSheetScreens(val route: String) { - data object GenerateCollectionSheetScreen : CollectionSheetScreens("generate_collection_sheet_route") + data object GenerateCollectionSheetScreen : + CollectionSheetScreens("generate_collection_sheet_route") - data object IndividualCollectionSheetScreen : CollectionSheetScreens("individual_collection_sheet_route") + data object IndividualCollectionSheetScreen : + CollectionSheetScreens("individual_collection_sheet_route") - data object IndividualCollectionSheetDetailScreen : CollectionSheetScreens("individual_collection_sheet_detail/{${Constants.INDIVIDUAL_SHEET}}") { + data object PaymentDetailsScreen : + CollectionSheetScreens("payment_details_route/{${Constants.ADAPTER_POSITION}}/{${Constants.PAYLOAD}}/{${Constants.PAYMENT_LIST}}/{${Constants.LOAN_AND_CLIENT}}/{${Constants.PAYMENT_OPTIONS}}/{${Constants.CLIENT_ID}}") { + fun argument( + position: Int, + payload: String, + paymentTypeOptionsName: String, + loansAndClientName: String, + paymentTypeOptions: String, + clientId: Int + ): String { + return "payment_details_route/$position/$payload/$paymentTypeOptionsName/$loansAndClientName/$paymentTypeOptions/$clientId" + } + } + + data object IndividualCollectionSheetDetailScreen : + CollectionSheetScreens("individual_collection_sheet_detail/{${Constants.INDIVIDUAL_SHEET}}") { fun argument(sheet: IndividualCollectionSheet): String { val gson = Gson() val sheetInGsonString = gson.toJson(sheet) diff --git a/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/new_individual_collection_sheet/ui/NewIndividualCollectionSheetScreen.kt b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/new_individual_collection_sheet/ui/NewIndividualCollectionSheetScreen.kt index 9d6c24eb387..df366c2a880 100644 --- a/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/new_individual_collection_sheet/ui/NewIndividualCollectionSheetScreen.kt +++ b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/new_individual_collection_sheet/ui/NewIndividualCollectionSheetScreen.kt @@ -274,7 +274,7 @@ fun NewIndividualCollectionSheetScreen( .weight(1f) .padding(16.dp), contentPadding = PaddingValues(), - enabled = selectedStaff != "" && selectedOffice != "", +// enabled = selectedOffice != "", colors = ButtonDefaults.buttonColors( containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary ) diff --git a/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/payment_details/PaymentDetailsScreen.kt b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/payment_details/PaymentDetailsScreen.kt new file mode 100644 index 00000000000..f199f64902c --- /dev/null +++ b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/payment_details/PaymentDetailsScreen.kt @@ -0,0 +1,396 @@ +package com.mifos.feature.individual_collection_sheet.payment_details + +import android.graphics.drawable.Drawable +import android.util.Log +import androidx.compose.foundation.Image +import androidx.compose.foundation.clickable +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.verticalScroll +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedCard +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.core.content.ContentProviderCompat.requireContext +import androidx.hilt.navigation.compose.hiltViewModel +import coil.compose.AsyncImage +import coil.request.ImageResult +import com.mifos.core.designsystem.component.MifosOutlinedTextField +import com.mifos.core.designsystem.component.MifosTextFieldDropdown +import com.mifos.core.designsystem.theme.BluePrimary +import com.mifos.core.designsystem.theme.BluePrimaryDark +import com.mifos.core.model.BulkRepaymentTransactions +import com.mifos.core.network.model.IndividualCollectionSheetPayload +import com.mifos.core.network.utils.ImageLoaderUtils +import com.mifos.core.objects.accounts.loan.PaymentTypeOptions +import com.mifos.core.objects.collectionsheet.LoanAndClientName +import com.mifos.core.objects.collectionsheet.LoanCollectionSheet +import com.mifos.feature.collection_sheet.R +import kotlinx.coroutines.launch + +/** + * Created by Pronay Sarker on 24/08/2024 (4:20 PM) + */ +@Composable +fun PaymentDetailsScreenRoute(modifier: Modifier = Modifier) { + + val viewModel: PaymentDetailsViewModel = hiltViewModel() + + PaymentDetailsScreenContent( + clientId = viewModel.clientId, + position = viewModel.position, + payload = viewModel.individualCollectionSheetPayload, + loanAndClientNameItem = viewModel.loanAndClientName, + paymentTypeOptionList = viewModel.paymentTypeOptionsName, + paymentTypeOptions = viewModel.paymentTypeOptions, + getClientImage = { viewModel.getClientImageUrl(it) } + ) +} + +@Composable +fun PaymentDetailsScreenContent( + clientId: Int, + position: Int, + payload: IndividualCollectionSheetPayload, + loanAndClientNameItem: LoanAndClientName, + paymentTypeOptionList: List, + paymentTypeOptions: List, + getClientImage: (Int) -> ImageResult? +) { + val loanCollectionSheetItem = loanAndClientNameItem?.loan + val scrollState = rememberScrollState() + + val bulkRepaymentTransactions by rememberSaveable { mutableStateOf(BulkRepaymentTransactions()) } + var totalDues: String by rememberSaveable { + mutableStateOf( + loanCollectionSheetItem?.totalDue?.toString() ?: "0.0" + ) + } + var paymentType by rememberSaveable { mutableStateOf("") } + val totalCharges by rememberSaveable { mutableStateOf("") } + var accountNumber by rememberSaveable { mutableStateOf("") } + var chequeNumber by rememberSaveable { mutableStateOf("") } + var routingCode by rememberSaveable { mutableStateOf("") } + var receiptNumber by rememberSaveable { mutableStateOf("") } + var bankNumber by rememberSaveable { mutableStateOf("") } + + var showAdditionalDetails by rememberSaveable { mutableStateOf(true) } + var noPaymentVisibility by rememberSaveable { mutableStateOf(true) } + + fun onSaveAdditionalItem(transaction: BulkRepaymentTransactions, position: Int) { + payload!!.bulkRepaymentTransactions[position] = transaction + } + + fun onShowSheetMandatoryItem(transaction: BulkRepaymentTransactions, position: Int) { + payload!!.bulkRepaymentTransactions[position] = transaction + } + + fun cancelAdditional() { //done + val charge1: Double = + if (totalCharges.isNotEmpty()) totalCharges.toDoubleOrNull() ?: 0.0 else 0.0 + val charge2: Double = if (totalDues.isNotEmpty()) totalDues.toDoubleOrNull() ?: 0.0 else 0.0 + + bulkRepaymentTransactions.loanId = loanAndClientNameItem?.loan!!.loanId + bulkRepaymentTransactions.transactionAmount = charge1 + charge2 + showAdditionalDetails = false + bulkRepaymentTransactions.paymentTypeId = null + bulkRepaymentTransactions.accountNumber = null + bulkRepaymentTransactions.checkNumber = null + bulkRepaymentTransactions.routingCode = null + bulkRepaymentTransactions.receiptNumber = null + bulkRepaymentTransactions.bankNumber = null + onSaveAdditionalItem(bulkRepaymentTransactions, position) + } + + fun saveAdditional() { + var isAnyDetailNull = false + + bulkRepaymentTransactions.loanId = loanAndClientNameItem?.loan!!.loanId + val charge1: Double = + if (totalCharges.isNotEmpty()) totalCharges.toDoubleOrNull() ?: 0.0 else 0.0 + val charge2: Double = if (totalDues.isNotEmpty()) totalDues.toDoubleOrNull() ?: 0.0 else 0.0 + + bulkRepaymentTransactions.transactionAmount = (charge1 + charge2) + + if (accountNumber.isNotEmpty()) { + bulkRepaymentTransactions.accountNumber = accountNumber + } else isAnyDetailNull = true + + if (chequeNumber.isNotEmpty()) { + bulkRepaymentTransactions.checkNumber = chequeNumber + } else isAnyDetailNull = true + + if (routingCode.isNotEmpty()) { + bulkRepaymentTransactions.routingCode = routingCode + } else isAnyDetailNull = true + + if (receiptNumber.isNotEmpty()) { + bulkRepaymentTransactions.receiptNumber = receiptNumber + } else isAnyDetailNull = true + + if (bankNumber.isNotEmpty()) { + bulkRepaymentTransactions.bankNumber = bankNumber + } else isAnyDetailNull = true + + if (!isAnyDetailNull) { + noPaymentVisibility = false + } + onSaveAdditionalItem(bulkRepaymentTransactions, position) + showAdditionalDetails = false + } + + LaunchedEffect(key1 = Unit) { + val defaultBulkRepaymentTransaction = BulkRepaymentTransactions() + if (loanCollectionSheetItem != null) { + defaultBulkRepaymentTransaction.loanId = loanCollectionSheetItem.loanId + defaultBulkRepaymentTransaction.transactionAmount = + loanCollectionSheetItem.chargesDue + loanCollectionSheetItem.totalDue + } + + onShowSheetMandatoryItem(defaultBulkRepaymentTransaction, position) + } + + Column( + modifier = Modifier + .fillMaxSize() + .verticalScroll(scrollState) + ) { + OutlinedCard( + modifier = Modifier + .fillMaxWidth() + .padding(16.dp), colors = CardDefaults.cardColors( + containerColor = Color.White + ) + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding(16.dp), + verticalAlignment = Alignment.CenterVertically, + + ) { + Column( + modifier = Modifier + .weight(1f) + .padding(end = 16.dp) + ) { + Text( + text = loanAndClientNameItem?.clientName ?: "This is Tv name", + style = TextStyle( + fontSize = 24.sp, fontWeight = FontWeight.Bold + ) + ) + + Spacer(modifier = Modifier.height(16.dp)) + + Text( + text = "${loanCollectionSheetItem?.productShortName} (#${loanCollectionSheetItem?.accountId})", + color = Color.DarkGray.copy(alpha = .7f), + style = TextStyle( + fontWeight = FontWeight.Bold + ) + ) + + Spacer(modifier = Modifier.height(16.dp)) + + MifosOutlinedTextField( + modifier = Modifier.fillMaxWidth(), + value = totalDues, + onValueChange = { totalDues = it }, + label = stringResource(id = R.string.feature_collection_sheet_total_due), + error = null, + keyboardType = KeyboardType.Number + ) + + Spacer(modifier = Modifier.height(16.dp)) + + Text( + text = stringResource(id = R.string.feature_collection_sheet_total_charges) + " : " + loanCollectionSheetItem?.chargesDue, + style = MaterialTheme.typography.bodyLarge, + fontWeight = FontWeight.Bold + ) + } + Column( + modifier = Modifier + .weight(.3f) + .fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally + ) { + AsyncImage( + modifier = Modifier.size(60.dp), + model = getClientImage(clientId) + ?: R.drawable.feature_collection_sheet_ic_dp_placeholder, + contentDescription = null, + contentScale = ContentScale.FillBounds + ) + } + } + } + + Button(modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp) + .height(50.dp), + colors = ButtonDefaults.buttonColors( + containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary + ), + onClick = { + showAdditionalDetails = !showAdditionalDetails + }) { + Text(text = stringResource(id = R.string.feature_collection_sheet_add_payment_detail)) + } + + if (noPaymentVisibility) { + Text( + text = stringResource(id = R.string.feature_collection_sheet_no_payment_added), + style = MaterialTheme.typography.bodyMedium, + modifier = Modifier + .align(Alignment.CenterHorizontally) + .padding(vertical = 16.dp), + color = Color.Gray, + ) + } + + if (showAdditionalDetails) { + OutlinedCard( + modifier = Modifier.padding(horizontal = 16.dp), colors = CardDefaults.cardColors( + containerColor = Color.White + ) + ) { + Column( + modifier = Modifier.padding(vertical = 16.dp) + ) { + MifosTextFieldDropdown( + label = R.string.feature_collection_sheet_payment_type, + value = paymentType, + onValueChanged = { paymentType = it }, + onOptionSelected = { index, value -> + paymentType = value + bulkRepaymentTransactions.paymentTypeId = paymentTypeOptions!![index].id + }, + options = paymentTypeOptionList ?: emptyList(), + readOnly = true + ) + + Spacer(modifier = Modifier.height(16.dp)) + + MifosOutlinedTextField( + value = accountNumber, + onValueChange = { accountNumber = it }, + label = stringResource(id = R.string.feature_collection_sheet_account_number), + error = null + ) + + Spacer(modifier = Modifier.height(16.dp)) + + MifosOutlinedTextField( + value = chequeNumber, + onValueChange = { chequeNumber = it }, + label = stringResource(id = R.string.feature_collection_sheet_cheque_number), + error = null + ) + + Spacer(modifier = Modifier.height(16.dp)) + + MifosOutlinedTextField( + value = routingCode, + onValueChange = { routingCode = it }, + label = stringResource(id = R.string.feature_collection_sheet_routing_code), + error = null + ) + + Spacer(modifier = Modifier.height(16.dp)) + + MifosOutlinedTextField( + value = receiptNumber, + onValueChange = { receiptNumber = it }, + label = stringResource(id = R.string.feature_collection_sheet_receipt_number), + error = null + ) + + Spacer(modifier = Modifier.height(16.dp)) + + MifosOutlinedTextField( + value = bankNumber, + onValueChange = { bankNumber = it }, + label = stringResource(id = R.string.feature_collection_sheet_bank_number), + error = null + ) + + Spacer(modifier = Modifier.height(16.dp)) + + Row( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp), + horizontalArrangement = Arrangement.SpaceBetween + ) { + Button(modifier = Modifier.height(50.dp), + colors = ButtonDefaults.buttonColors( + containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary + ), + onClick = { cancelAdditional() }) { + Text(text = stringResource(id = R.string.feature_collection_sheet_cancel)) + } + + Button(modifier = Modifier.height(50.dp), + colors = ButtonDefaults.buttonColors( + containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary + ), + onClick = { saveAdditional() }) { + Text(text = stringResource(id = R.string.feature_collection_sheet_save)) + } + } + } + } + } + } +} + +@Composable +@Preview(showBackground = true) +fun PreviewPaymentDetails(modifier: Modifier = Modifier) { + PaymentDetailsScreenContent( + clientId = 0, + position = 0, + payload = IndividualCollectionSheetPayload(), + loanAndClientNameItem = LoanAndClientName(id = 2, loan = null, clientName = ""), + paymentTypeOptionList = emptyList(), + paymentTypeOptions = emptyList(), + getClientImage = { null } + ) +} + + diff --git a/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/payment_details/PaymentDetailsViewModel.kt b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/payment_details/PaymentDetailsViewModel.kt new file mode 100644 index 00000000000..d2a2023280a --- /dev/null +++ b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/payment_details/PaymentDetailsViewModel.kt @@ -0,0 +1,45 @@ +package com.mifos.feature.individual_collection_sheet.payment_details + +import androidx.lifecycle.SavedStateHandle +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import coil.request.ImageResult +import com.google.gson.Gson +import com.mifos.core.common.utils.Constants +import com.mifos.core.network.model.IndividualCollectionSheetPayload +import com.mifos.core.network.utils.ImageLoaderUtils +import com.mifos.core.objects.accounts.loan.PaymentTypeOptions +import com.mifos.core.objects.collectionsheet.LoanAndClientName +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import javax.inject.Inject + +@HiltViewModel +class PaymentDetailsViewModel @Inject constructor( + private val imageLoaderUtils: ImageLoaderUtils, + savedStateHandle: SavedStateHandle +) : ViewModel() { + private val payloadArg = savedStateHandle.getStateFlow(key = Constants.PAYLOAD, initialValue = "") + private val paymentListArg = savedStateHandle.getStateFlow(key = Constants.PAYMENT_LIST, initialValue = "") + private val loanAndClientNameArg = savedStateHandle.getStateFlow(key = Constants.LOAN_AND_CLIENT, initialValue = "") + private val paymentOptionsArg = savedStateHandle.getStateFlow(key = Constants.PAYMENT_OPTIONS, initialValue = "") + + private val decodedPosition = savedStateHandle.get(Constants.ADAPTER_POSITION)?.toIntOrNull() ?: 0 + private val decodedClientId = savedStateHandle.get(Constants.CLIENT_ID)?.toIntOrNull() ?: 0 + + val clientId = decodedClientId + val position = decodedPosition + val individualCollectionSheetPayload: IndividualCollectionSheetPayload = Gson().fromJson(payloadArg.value, IndividualCollectionSheetPayload::class.java) + val paymentTypeOptionsName = Gson().fromJson(paymentListArg.value, Array::class.java).toList() + val loanAndClientName: LoanAndClientName = Gson().fromJson(loanAndClientNameArg.value, LoanAndClientName::class.java) + val paymentTypeOptions = Gson().fromJson(paymentOptionsArg.value, Array::class.java).toList() + + fun getClientImageUrl(clientId: Int) : ImageResult? { + var image : ImageResult? = null + viewModelScope.launch (Dispatchers.IO) { + image = imageLoaderUtils.loadImage(clientId) + } + return image + } +} diff --git a/feature/collection-sheet/src/main/res/values/strings.xml b/feature/collection-sheet/src/main/res/values/strings.xml index bb847c6e902..abd3cdad754 100644 --- a/feature/collection-sheet/src/main/res/values/strings.xml +++ b/feature/collection-sheet/src/main/res/values/strings.xml @@ -18,11 +18,20 @@ Date: Member: Fill Now - + No Payment Added Failed to Save Collection Sheet Collection Sheet Saved Successfully Total Charges Total due + Add Payment Detail + Account Number + Cheque Number + Routing Code + Receipt Number + Bank Number + Save + + Collection Details Attendance Type diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt index 392db004b59..368f79ebd30 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt @@ -190,9 +190,9 @@ fun Navigation( individualCollectionSheetNavGraph( onBackPressed = { navController.popBackStack() }, navController = navController, - navigateToPaymentDetails = { _, _, _, _, _, _ -> -// TODO() navigate to payment details - } +// navigateToPaymentDetails = { _, _, _, _, _, _ -> +//// TODO() navigate to payment details +// } ) generateCollectionSheetScreen(onBackPressed = navController::popBackStack) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/GenerateCollectionSheetActivity.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/GenerateCollectionSheetActivity.kt index 741516f0f0f..d0b6e4a3bf1 100755 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/GenerateCollectionSheetActivity.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/GenerateCollectionSheetActivity.kt @@ -12,11 +12,13 @@ import com.mifos.core.network.model.IndividualCollectionSheetPayload import com.mifos.mifosxdroid.R import com.mifos.mifosxdroid.core.MifosBaseActivity import com.mifos.mifosxdroid.databinding.ActivityToolbarContainerBinding -import com.mifos.mifosxdroid.online.collectionsheetindividualdetails.PaymentDetailsFragment.OnPayloadSelectedListener +//import com.mifos.mifosxdroid.online.collectionsheetindividualdetails.PaymentDetailsFragment.OnPayloadSelectedListener import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint -class GenerateCollectionSheetActivity : MifosBaseActivity(), OnPayloadSelectedListener { +class GenerateCollectionSheetActivity : MifosBaseActivity() +// OnPayloadSelectedListener +{ private lateinit var binding: ActivityToolbarContainerBinding @@ -48,7 +50,7 @@ class GenerateCollectionSheetActivity : MifosBaseActivity(), OnPayloadSelectedLi return true } - override fun onPayloadSelected(payload: IndividualCollectionSheetPayload?) { - this.payload = payload - } +// override fun onPayloadSelected(payload: IndividualCollectionSheetPayload?) { +// this.payload = payload +// } } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.kt index 132205a0625..d65f1e0859d 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividual/IndividualCollectionSheetFragment.kt @@ -40,13 +40,12 @@ class IndividualCollectionSheetFragment : MifosBaseFragment() { repaymentDate: String, individualCollectionSheet: IndividualCollectionSheet ) { - val action = - IndividualCollectionSheetFragmentDirections.actionIndividualCollectionSheetFragmentToIndividualCollectionSheetDetailsFragment( + val action = IndividualCollectionSheetFragmentDirections.actionIndividualCollectionSheetFragmentToIndividualCollectionSheetDetailsFragment( individualCollectionSheet, SimpleDateFormat( - "dd MMMM yyyy", + "dd MM yyyy", Locale.getDefault() ).format(System.currentTimeMillis()), repaymentDate ) findNavController().navigate(action) } -} \ No newline at end of file +} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/PaymentDetailsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/PaymentDetailsFragment.kt index 7f620ca3918..f735e388d20 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/PaymentDetailsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/collectionsheetindividualdetails/PaymentDetailsFragment.kt @@ -1,3 +1,4 @@ + package com.mifos.mifosxdroid.online.collectionsheetindividualdetails import android.app.Activity @@ -8,11 +9,15 @@ import android.view.ViewGroup import android.widget.AdapterView import android.widget.AdapterView.OnItemSelectedListener import android.widget.ArrayAdapter +import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.navigation.fragment.navArgs import com.mifos.core.model.BulkRepaymentTransactions import com.mifos.core.network.model.IndividualCollectionSheetPayload import com.mifos.core.objects.accounts.loan.PaymentTypeOptions import com.mifos.core.objects.collectionsheet.LoanAndClientName +import com.mifos.feature.individual_collection_sheet.generate_collection_sheet.GenerateCollectionSheetScreen +import com.mifos.feature.individual_collection_sheet.payment_details.PaymentDetailsScreenContent import com.mifos.mifosxdroid.R import com.mifos.mifosxdroid.core.MifosBaseFragment import com.mifos.mifosxdroid.databinding.AddPaymentDetailBinding @@ -85,10 +90,14 @@ class PaymentDetailsFragment : MifosBaseFragment(), View.OnClickListener, OnItem String.format(Locale.getDefault(), "%.2f", it) } ) + /** + * problem1 + */ ImageLoaderUtils.loadImage( requireContext(), clientId, binding.ivUserPicture ) + val defaultBulkRepaymentTransaction = BulkRepaymentTransactions() if (loanCollectionSheetItem != null) { defaultBulkRepaymentTransaction.loanId = loanCollectionSheetItem.loanId @@ -123,13 +132,12 @@ class PaymentDetailsFragment : MifosBaseFragment(), View.OnClickListener, OnItem } private fun cancelAdditional() { - bulkRepaymentTransaction.loanId = loanAndClientNameItem - ?.loan!!.loanId - val charge1: Double = if (binding.tvTotalCharges.text - .toString().isNotEmpty() - ) binding.tvTotalCharges.text.toString().toDouble() else 0.0 + bulkRepaymentTransaction.loanId = loanAndClientNameItem?.loan!!.loanId + val charge1: Double = if (binding.tvTotalCharges.text.toString().isNotEmpty()) + binding.tvTotalCharges.text.toString().toDouble() else 0.0 val charge2: Double = if (binding.etTotalDue.text.toString().isNotEmpty() ) binding.etTotalDue.text.toString().toDouble() else 0.0 + bulkRepaymentTransaction.transactionAmount = charge1 + charge2 binding.tableAdditionalDetails.visibility = View.GONE bulkRepaymentTransaction.paymentTypeId = null @@ -143,8 +151,7 @@ class PaymentDetailsFragment : MifosBaseFragment(), View.OnClickListener, OnItem private fun saveAdditional() { var isAnyDetailNull = false - bulkRepaymentTransaction.loanId = loanAndClientNameItem - ?.loan!!.loanId + bulkRepaymentTransaction.loanId = loanAndClientNameItem?.loan!!.loanId val charge1: Double = if (binding.tvTotalCharges.text.toString().isNotEmpty()) binding.tvTotalCharges.text.toString().toDouble() else 0.0 val charge2: Double = if (binding.etTotalDue.text.toString().isNotEmpty()) { diff --git a/mifosng-android/src/main/res/layout/add_payment_detail.xml b/mifosng-android/src/main/res/layout/add_payment_detail.xml index 9e3af6fd972..ed50090d297 100644 --- a/mifosng-android/src/main/res/layout/add_payment_detail.xml +++ b/mifosng-android/src/main/res/layout/add_payment_detail.xml @@ -34,6 +34,7 @@ android:layout_marginLeft="16dp" android:layout_marginTop="16dp" android:textSize="24sp" + android:text="This is tv size" android:textStyle="bold" /> @@ -148,7 +150,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dp" - android:visibility="gone"> + android:visibility="visible"> @@ -198,6 +200,7 @@ android:layout_height="wrap_content" android:layout_weight="0.5" android:hint="@string/cheque_number" + android:text="24343" android:imeOptions="actionNext" android:tag="cheque_number" /> @@ -244,6 +247,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.5" + text="@string/bank_number" /> android:text="@string/bank_number" />