Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ that can be used as a dependency in any other wallet based project. It is develo
| :feature:home | Done | ✅ | ✅ | ❔ | ✅ | ❔ |
| :feature:profile | Done | ✅ | ✅ | ❔ | ✅ | ❔ |
| :feature:settings | Done | ✅ | ✅ | ❔ | ✅ | ❔ |
| :feature:payments | Done | ✅ | ✅ | | ✅ | ❔ |
| :feature:finance | Done | ✅ | ✅ | | ✅ | ❔ |
| :feature:account | Done | ✅ | ✅ | | ✅ | ❔ |
| :feature:invoices | Not started | ❌ | | | | |
| :feature:payments | Done | ✅ | ✅ | | ✅ | ❔ |
| :feature:finance | Done | ✅ | ✅ | | ✅ | ❔ |
| :feature:account | Done | ✅ | ✅ | | ✅ | ❔ |
| :feature:invoices | Done | ✅ | | | | |
| :feature:kyc | Not started | ❌ | ❌ | ❌ | ❌ | ❌ |
| :feature:make-transfer | Not started | ❌ | ❌ | ❌ | ❌ | ❌ |
| :feature:merchants | Not started | ❌ | ❌ | ❌ | ❌ | ❌ |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ package org.mifospay.core.data.repository

import kotlinx.coroutines.flow.Flow
import org.mifospay.core.common.DataState
import org.mifospay.core.network.model.GenericResponse
import org.mifospay.core.network.model.entity.Invoice
import org.mifospay.core.model.datatables.invoice.Invoice
import org.mifospay.core.model.datatables.invoice.InvoiceEntity

interface InvoiceRepository {
suspend fun getInvoice(clientId: Int, invoiceId: Int): Flow<DataState<Invoice>>
fun getInvoice(clientId: Long, invoiceId: Long): Flow<DataState<Invoice>>

suspend fun getInvoices(clientId: Int): Flow<DataState<List<Invoice>>>
fun getInvoices(clientId: Long): Flow<DataState<List<Invoice>>>

suspend fun createInvoice(clientId: Int, invoice: Invoice): DataState<Unit>
suspend fun createInvoice(clientId: Long, invoice: InvoiceEntity): DataState<String>

suspend fun updateInvoice(
clientId: Int,
invoiceId: Int,
invoice: Invoice,
): Flow<DataState<GenericResponse>>
clientId: Long,
invoiceId: Long,
invoice: InvoiceEntity,
): DataState<String>

suspend fun deleteInvoice(clientId: Int, invoiceId: Int): Flow<DataState<GenericResponse>>
suspend fun deleteInvoice(clientId: Long, invoiceId: Long): DataState<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,78 @@ package org.mifospay.core.data.repositoryImp

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.withContext
import org.mifospay.core.common.DataState
import org.mifospay.core.common.asDataStateFlow
import org.mifospay.core.data.repository.InvoiceRepository
import org.mifospay.core.model.datatables.invoice.Invoice
import org.mifospay.core.model.datatables.invoice.InvoiceEntity
import org.mifospay.core.network.FineractApiManager
import org.mifospay.core.network.model.GenericResponse
import org.mifospay.core.network.model.entity.Invoice

class InvoiceRepositoryImpl(
private val apiManager: FineractApiManager,
private val ioDispatcher: CoroutineDispatcher,
) : InvoiceRepository {
override suspend fun getInvoice(clientId: Int, invoiceId: Int): Flow<DataState<Invoice>> {
return apiManager.invoiceApi.getInvoice(clientId, invoiceId).asDataStateFlow().flowOn(ioDispatcher)
override fun getInvoice(clientId: Long, invoiceId: Long): Flow<DataState<Invoice>> {
return apiManager.invoiceApi
.getInvoice(clientId, invoiceId)
.onStart { DataState.Loading }
.catch { DataState.Error(it, null) }
.map { it.first() }
.asDataStateFlow()
.flowOn(ioDispatcher)
}

override suspend fun getInvoices(clientId: Int): Flow<DataState<List<Invoice>>> {
return apiManager.invoiceApi.getInvoices(clientId).asDataStateFlow().flowOn(ioDispatcher)
override fun getInvoices(clientId: Long): Flow<DataState<List<Invoice>>> {
return apiManager.invoiceApi
.getInvoices(clientId)
.onStart { DataState.Loading }
.catch { DataState.Error(it, null) }
.asDataStateFlow()
.flowOn(ioDispatcher)
}

override suspend fun createInvoice(clientId: Int, invoice: Invoice): DataState<Unit> {
override suspend fun createInvoice(clientId: Long, invoice: InvoiceEntity): DataState<String> {
return try {
DataState.Success(apiManager.invoiceApi.addInvoice(clientId, invoice))
withContext(ioDispatcher) {
apiManager.invoiceApi.addInvoice(clientId, invoice)
}

DataState.Success("Invoice created successfully")
} catch (e: Exception) {
DataState.Error(e)
DataState.Error(e, null)
}
}

override suspend fun updateInvoice(
clientId: Int,
invoiceId: Int,
invoice: Invoice,
): Flow<DataState<GenericResponse>> {
return apiManager.invoiceApi
.updateInvoice(clientId, invoiceId, invoice).asDataStateFlow()
.flowOn(ioDispatcher)
clientId: Long,
invoiceId: Long,
invoice: InvoiceEntity,
): DataState<String> {
return try {
withContext(ioDispatcher) {
apiManager.invoiceApi.updateInvoice(clientId, invoiceId, invoice)
}

DataState.Success("Invoice updated successfully")
} catch (e: Exception) {
DataState.Error(e, null)
}
}

override suspend fun deleteInvoice(
clientId: Int,
invoiceId: Int,
): Flow<DataState<GenericResponse>> {
return apiManager.invoiceApi
.deleteInvoice(clientId, invoiceId).asDataStateFlow()
.flowOn(ioDispatcher)
override suspend fun deleteInvoice(clientId: Long, invoiceId: Long): DataState<String> {
return try {
withContext(ioDispatcher) {
apiManager.invoiceApi.deleteInvoice(clientId, invoiceId)
}

DataState.Success("Invoice deleted successfully")
} catch (e: Exception) {
DataState.Error(e, null)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
*/
package org.mifospay.core.model.datatables.invoice

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.mifospay.core.common.Parcelable
import org.mifospay.core.common.Parcelize

@Serializable
@Parcelize
data class Invoice(
val id: Long,
@SerialName("client_id")
val clientId: Long,
val consumerId: String,
val consumerName: String,
val amount: Double,
@SerialName("itemsbought")
val itemsBought: String,
val status: Long,
val transactionId: String,
val invoiceId: Long,
val title: String,
val date: String,
@SerialName("created_at")
val createdAt: List<Long>,
@SerialName("updated_at")
val updatedAt: List<Long>,
) : Parcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
*/
package org.mifospay.core.model.datatables.invoice

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class InvoiceEntity(
val id: Long,
val invoiceId: Long,
val consumerId: String,
val consumerName: String,
val amount: Double,
@SerialName("itemsbought")
val itemsBought: String,
val status: Long,
val transactionId: String,
val title: String,
val date: String,
val locale: String,
val dateFormat: String,
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,36 @@ import de.jensklingenberg.ktorfit.http.POST
import de.jensklingenberg.ktorfit.http.PUT
import de.jensklingenberg.ktorfit.http.Path
import kotlinx.coroutines.flow.Flow
import org.mifospay.core.network.model.GenericResponse
import org.mifospay.core.network.model.entity.Invoice
import org.mifospay.core.model.datatables.invoice.Invoice
import org.mifospay.core.model.datatables.invoice.InvoiceEntity
import org.mifospay.core.network.utils.ApiEndPoints

// TODO:: Fix this endpoints, there's no such endpoint for invoices
interface InvoiceService {
@GET(ApiEndPoints.DATATABLES + "/invoices/{clientId}")
suspend fun getInvoices(@Path("clientId") clientId: Int): Flow<List<Invoice>>
@GET(ApiEndPoints.DATATABLES + "/invoice/{clientId}")
fun getInvoices(@Path("clientId") clientId: Long): Flow<List<Invoice>>

@GET(ApiEndPoints.DATATABLES + "/invoices/{clientId}/{invoiceId}")
suspend fun getInvoice(
@Path("clientId") clientId: Int,
@Path("invoiceId") invoiceId: Int,
): Flow<Invoice>
@GET(ApiEndPoints.DATATABLES + "/invoice/{clientId}/{invoiceId}")
fun getInvoice(
@Path("clientId") clientId: Long,
@Path("invoiceId") invoiceId: Long,
): Flow<List<Invoice>>

@POST(ApiEndPoints.DATATABLES + "/invoices/{clientId}")
@POST(ApiEndPoints.DATATABLES + "/invoice/{clientId}")
suspend fun addInvoice(
@Path("clientId") clientId: Int,
@Body invoice: Invoice?,
@Path("clientId") clientId: Long,
@Body invoice: InvoiceEntity,
): Unit

@PUT(ApiEndPoints.DATATABLES + "/invoices/{clientId}/{invoiceId}")
@PUT(ApiEndPoints.DATATABLES + "/invoice/{clientId}/{invoiceId}")
suspend fun updateInvoice(
@Path("clientId") clientId: Int,
@Path("invoiceId") invoiceId: Int,
@Body invoice: Invoice?,
): Flow<GenericResponse>
@Path("clientId") clientId: Long,
@Path("invoiceId") invoiceId: Long,
@Body invoice: InvoiceEntity,
): Unit

@DELETE(ApiEndPoints.DATATABLES + "/invoices/{clientId}/{invoiceId}")
@DELETE(ApiEndPoints.DATATABLES + "/invoice/{clientId}/{invoiceId}")
suspend fun deleteInvoice(
@Path("clientId") clientId: Int,
@Path("invoiceId") invoiceId: Int,
): Flow<GenericResponse>
@Path("clientId") clientId: Long,
@Path("invoiceId") invoiceId: Long,
): Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ fun AvatarBox(
fun AvatarBox(
icon: ImageVector,
size: Int = 40,
modifier: Modifier = Modifier,
backgroundColor: Color = MaterialTheme.colorScheme.surfaceContainer,
contentColor: Color = contentColorFor(backgroundColor),
) {
Box(
modifier = Modifier
modifier = modifier
.size(size.dp)
.clip(CircleShape)
.background(backgroundColor),
Expand All @@ -70,7 +72,7 @@ fun AvatarBox(
Icon(
imageVector = icon,
contentDescription = "Avatar",
tint = contentColorFor(backgroundColor),
tint = contentColor,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ private fun SavingAccountSummaryCard(

@Composable
private inline fun RowBlock(
crossinline content:
@Composable()
(RowScope.() -> Unit),
crossinline content: @Composable (RowScope.() -> Unit),
) {
Box {
Row(
Expand Down
18 changes: 14 additions & 4 deletions feature/invoices/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@
* See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
*/
plugins {
alias(libs.plugins.mifospay.android.feature)
alias(libs.plugins.mifospay.android.library.compose)
alias(libs.plugins.mifospay.cmp.feature)
alias(libs.plugins.kotlin.parcelize)
}

android {
namespace = "org.mifospay.invoices"
namespace = "org.mifospay.feature.invoices"
}

dependencies {}
kotlin {
sourceSets {
commonMain.dependencies {
implementation(compose.ui)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
}
}
}
Empty file.
Loading