Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #963 from jevo160296/skip_all_overdue
Browse files Browse the repository at this point in the history
Skip all overdue
  • Loading branch information
ILIYANGERMANOV authored May 28, 2022
2 parents 3ccd21c + 5b55f18 commit 2ab4dc3
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,66 @@ class PlannedPaymentsLogic(
}
}
}

suspend fun payOrGet(
transactions: List<Transaction>,
syncTransaction: Boolean = true,
skipTransaction: Boolean = false,
onUpdateUI: suspend (paidTransactions: List<Transaction>) -> Unit
){
val paidTransactions = transactions.filter { (it.dueDate == null || it.dateTime != null).not() }

if (paidTransactions.count() == 0) return

paidTransactions.map {
it.copy(
dueDate = null,
dateTime = timeNowUTC(),
isSynced = false
)
}

val plannedPaymentRules = ioThread {
paidTransactions.map { transaction ->
transaction.recurringRuleId?.let {
plannedPaymentRuleDao.findById(it)
}
}
}

ioThread {
if (skipTransaction)
paidTransactions.forEach {
paidTransaction -> transactionDao.flagDeleted(paidTransaction.id)
}
else
paidTransactions.forEach {
paidTransaction -> transactionDao.save(paidTransaction.toEntity())
}

plannedPaymentRules.forEach { plannedPaymentRule ->
if (plannedPaymentRule != null && plannedPaymentRule.oneTime) {
//delete paid oneTime planned payment rules
plannedPaymentRuleDao.flagDeleted(plannedPaymentRule.id)
}
}
}

onUpdateUI(paidTransactions)

ioThread {
paidTransactions.forEach{ paidTransaction ->
if (syncTransaction && !skipTransaction) {
transactionUploader.sync(paidTransaction)
}
}

plannedPaymentRules.forEach{ plannedPaymentRule ->
if (plannedPaymentRule != null && plannedPaymentRule.oneTime) {
//delete paid oneTime planned payment rules
plannedPaymentRuleUploader.delete(plannedPaymentRule.id)
}
}
}
}
}
1 change: 1 addition & 0 deletions app/src/main/java/com/ivy/wallet/ui/home/HomeEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ sealed class HomeEvent {

data class PayOrGetPlanned(val transaction: Transaction) : HomeEvent()
data class SkipPlanned(val transaction: Transaction) : HomeEvent()
data class SkipAllPlanned(val transactions: List<Transaction>) : HomeEvent()

data class DismissCustomerJourneyCard(val card: CustomerJourneyCardData) : HomeEvent()

Expand Down
20 changes: 18 additions & 2 deletions app/src/main/java/com/ivy/wallet/ui/home/HomeTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ fun BoxWithConstraintsScope.HomeTab(screen: Main) {
onSetPeriod = { onEvent(HomeEvent.SetPeriod(it)) },
onPayOrGet = { onEvent(HomeEvent.PayOrGetPlanned(it)) },
onSkipTransaction = { onEvent(HomeEvent.SkipPlanned(it)) },
onSkipAllTransactions = { onEvent(HomeEvent.SkipAllPlanned(it)) },
onDismissCustomerJourneyCard = { onEvent(HomeEvent.DismissCustomerJourneyCard(it)) },
onSelectNextMonth = { onEvent(HomeEvent.SelectNextMonth) },
onSelectPreviousMonth = { onEvent(HomeEvent.SelectPreviousMonth) }
Expand Down Expand Up @@ -143,6 +144,7 @@ private fun BoxWithConstraintsScope.UI(
onSelectNextMonth: () -> Unit = {},
onSelectPreviousMonth: () -> Unit = {},
onSkipTransaction: (Transaction) -> Unit = {},
onSkipAllTransactions: (List<Transaction>) -> Unit = {}
) {
val ivyContext = ivyWalletCtx()

Expand All @@ -152,6 +154,7 @@ private fun BoxWithConstraintsScope.UI(
mutableStateOf(null)
}
var moreMenuExpanded by remember { mutableStateOf(ivyContext.moreMenuExpanded) }
var skipAllModalVisible by remember { mutableStateOf(false) }
val setMoreMenuExpanded = { expanded: Boolean ->
moreMenuExpanded = expanded
ivyContext.setMoreMenuExpanded(expanded)
Expand Down Expand Up @@ -252,7 +255,8 @@ private fun BoxWithConstraintsScope.UI(

onPayOrGet = onPayOrGet,
onDismiss = onDismissCustomerJourneyCard,
onSkipTransaction = onSkipTransaction
onSkipTransaction = onSkipTransaction,
onSkipAllTransactions = { skipAllModalVisible = true }
)
}

Expand Down Expand Up @@ -303,6 +307,16 @@ private fun BoxWithConstraintsScope.UI(
) {
onSetPeriod(it)
}

DeleteModal(
visible = skipAllModalVisible,
title = stringResource(R.string.confirm_skip_all),
description = stringResource(R.string.confirm_skip_all_description),
dismiss = { skipAllModalVisible = false }
) {
onSkipAllTransactions(overdue)
skipAllModalVisible = false
}
}

@ExperimentalAnimationApi
Expand Down Expand Up @@ -351,6 +365,7 @@ fun HomeLazyColumn(
onPayOrGet: (Transaction) -> Unit,
onDismiss: (CustomerJourneyCardData) -> Unit,
onSkipTransaction: (Transaction) -> Unit = {},
onSkipAllTransactions: (List<Transaction>) -> Unit = {}
) {
val ivyContext = ivyWalletCtx()
val nav = navigation()
Expand Down Expand Up @@ -436,7 +451,8 @@ fun HomeLazyColumn(
R.string.no_transactions_description,
period.toDisplayLong(ivyContext.startDayOfMonth)
),
onSkipTransaction = onSkipTransaction
onSkipTransaction = onSkipTransaction,
onSkipAllTransactions = onSkipAllTransactions
)
}
}
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/ivy/wallet/ui/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class HomeViewModel @Inject constructor(
HomeEvent.HiddenBalanceClick -> onHiddenBalanceClick()
is HomeEvent.PayOrGetPlanned -> payOrGetPlanned(event.transaction)
is HomeEvent.SkipPlanned -> skipPlanned(event.transaction)
is HomeEvent.SkipAllPlanned -> skipAllPlanned(event.transactions)
is HomeEvent.SetPeriod -> setPeriod(event.period)
HomeEvent.SelectNextMonth -> nextMonth()
HomeEvent.SelectPreviousMonth -> previousMonth()
Expand Down Expand Up @@ -327,6 +328,24 @@ class HomeViewModel @Inject constructor(
stateVal()
}

private suspend fun skipAllPlanned(transactions: List<Transaction>) = suspend{
//transactions.forEach {
// plannedPaymentsLogic.payOrGet(
// transaction = it,
// skipTransaction = true
// ){
// reload()
// }
//}
plannedPaymentsLogic.payOrGet(
transactions = transactions,
skipTransaction = true
){
reload()
}
stateVal()
}

private suspend fun dismissCustomerJourneyCard(card: CustomerJourneyCardData) = suspend {
customerJourneyLogic.dismissCard(card)
} then {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
Expand All @@ -25,9 +26,8 @@ import com.ivy.wallet.domain.data.core.Transaction
import com.ivy.wallet.stringRes
import com.ivy.wallet.ui.EditTransaction
import com.ivy.wallet.ui.IvyWalletCtx
import com.ivy.wallet.ui.theme.Gray
import com.ivy.wallet.ui.theme.Orange
import com.ivy.wallet.ui.theme.Red
import com.ivy.wallet.ui.theme.*
import com.ivy.wallet.ui.theme.components.IvyButton
import com.ivy.wallet.ui.theme.components.IvyIcon
import kotlin.math.absoluteValue

Expand Down Expand Up @@ -55,6 +55,7 @@ fun LazyListScope.transactions(
emptyStateText: String,
dateDividerMarginTop: Dp? = null,
onSkipTransaction: (Transaction) -> Unit = {},
onSkipAllTransactions: (List<Transaction>) -> Unit = {}
) {
if (upcoming.isNotEmpty()) {
item {
Expand Down Expand Up @@ -103,6 +104,24 @@ fun LazyListScope.transactions(
}

if (overdueExpanded) {
item{
val isLightTheme = UI.colors.pure == White
IvyButton(
modifier = Modifier.padding(horizontal = 24.dp),
text = stringRes(R.string.skip_all),
wrapContentMode = false,
backgroundGradient = if (isLightTheme) Gradient(White, White) else Gradient(
Black,
Black
),
textStyle = UI.typo.b2.style(
color = if (isLightTheme) Black else White,
fontWeight = FontWeight.Bold
)
) {
onSkipAllTransactions(overdue)
}
}
items(overdue) {
TransactionCard(
baseCurrency = baseCurrency,
Expand Down Expand Up @@ -180,6 +199,12 @@ fun LazyListScope.transactions(
}
}

private fun onSkipAllClick(

){

}

private fun onTransactionClick(
nav: Navigation,
listState: LazyListState,
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,7 @@
<string name="home_category">البيت</string>
<string name="generating_report">يتم إنشاء التقرير …</string>
<string name="sort_by">ترتيب حسب</string>
<string name="skip_all">تخطي الكل</string>
<string name="confirm_skip_all">تأكيد تخطي الكل</string>
<string name="confirm_skip_all_description">هل أنت متأكد من أنك تريد تخطي جميع المعاملات المخطط لها المتأخرة؟</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-bg/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,7 @@
<string name="home_category">Дом</string>
<string name="generating_report">Generating report…</string>
<string name="sort_by">sortirane po</string>
<string name="skip_all">прескочете всички</string>
<string name="confirm_skip_all">Потвърдете пропускането на всички</string>
<string name="confirm_skip_all_description">Сигурни ли сте, че искате да пропуснете всички просрочени планирани операции?</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,7 @@
<string name="home_category">Hogar</string>
<string name="generating_report">Generando reporte…</string>
<string name="sort_by">" Ordenar por"</string>
<string name="skip_all">Saltar todo</string>
<string name="confirm_skip_all">Confirmar saltar todo</string>
<string name="confirm_skip_all_description">¿Está seguro de saltar todas las transacciones planeadas caducadas?</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,7 @@
<string name="home_category">Casa</string>
<string name="generating_report">Generazione report…</string>
<string name="sort_by">ordina per</string>
<string name="confirm_skip_all_description">Siete sicuri di voler saltare tutte le transazioni pianificate in ritardo?</string>
<string name="confirm_skip_all">Confermare il salto di tutti</string>
<string name="skip_all">Salta tutto</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,7 @@
<string name="home_category">Дом</string>
<string name="generating_report">Создание отчёта…</string>
<string name="sort_by">Сортировать по</string>
<string name="skip_all">Пропустить все</string>
<string name="confirm_skip_all">Подтвердить пропуск всех</string>
<string name="confirm_skip_all_description">Вы уверены, что хотите пропустить все просроченные запланированные операции?</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,7 @@
<string name="home_category">Home</string>
<string name="generating_report">Generating report…</string>
<string name="sort_by">Sort by</string>
<string name="skip_all">Skip all</string>
<string name="confirm_skip_all">Confirm skip all</string>
<string name="confirm_skip_all_description">Are you sure that you want to skip all overdue planned transactions?</string>
</resources>

0 comments on commit 2ab4dc3

Please sign in to comment.