Skip to content

Commit

Permalink
delete
Browse files Browse the repository at this point in the history
  • Loading branch information
lexwilliam committed Oct 1, 2024
1 parent f0ea84c commit 070bf13
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ data class TransactionDto(
val branchUUID: String? = null,
@JvmField @PropertyName("order_group")
val orderGroup: OrderGroupDto? = null,
val payments: Map<String, PaymentDto>? = null,
val refunds: Map<String, RefundDto>? = null,
val profit: Double? = null,
val customer: String? = null,
val fee: TransactionFeeDto? = null,
val tip: Double? = null,
@JvmField @PropertyName("created_by")
val createdBy: String? = null,
@JvmField @PropertyName("created_at")
Expand All @@ -32,11 +29,8 @@ data class TransactionDto(
uuid = uuid.validateUUID(),
branchUUID = branchUUID.validateUUID(),
orderGroup = orderGroup?.toDomain() ?: OrderGroupDto().toDomain(),
payments = payments?.map { it.value.toDomain() } ?: emptyList(),
refunds = refunds?.map { it.value.toDomain() } ?: emptyList(),
profit = profit ?: 0.0,
customer = customer ?: "",
fee = fee?.toDomain(),
tip = tip ?: 0.0,
createdBy = createdBy ?: "",
createdAt = createdAt?.toKtxInstant() ?: Instant.DISTANT_PAST,
deletedAt = deletedAt?.toKtxInstant()
Expand All @@ -48,15 +42,8 @@ data class TransactionDto(
uuid = domain.uuid.toString(),
branchUUID = domain.branchUUID.toString(),
orderGroup = OrderGroupDto.fromDomain(domain.orderGroup),
payments =
domain.payments
.associate { it.uuid.toString() to PaymentDto.fromDomain(it) },
refunds =
domain.refunds
.associate { it.uuid.toString() to RefundDto.fromDomain(it) },
profit = domain.profit,
customer = domain.customer,
fee = domain.fee?.let { TransactionFeeDto.fromDomain(it) },
tip = domain.tip,
createdBy = domain.createdBy,
createdAt = domain.createdAt.toTimestamp(),
deletedAt = domain.deletedAt?.toTimestamp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ data class Transaction(
val uuid: UUID,
val branchUUID: UUID,
val orderGroup: OrderGroup,
val payments: List<Payment>,
val refunds: List<Refund>,
val profit: Double,
val customer: String,
val fee: TransactionFee?,
val tip: Double,
val createdBy: String,
val createdAt: Instant,
val deletedAt: Instant? = null
Expand Down
1 change: 0 additions & 1 deletion feature/home/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ ktlint {
dependencies {
implementation(project(":data:user"))
implementation(project(":data:transaction"))
implementation(project(":data:log"))
implementation(project(":feature:transaction"))
implementation(project(":libraries:core"))
implementation(project(":libraries:core-ui"))
Expand Down
1 change: 0 additions & 1 deletion feature/order/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ dependencies {
implementation(project(":data:transaction"))
implementation(project(":data:branch"))
implementation(project(":data:user"))
implementation(project(":data:log"))
implementation(project(":libraries:core"))
implementation(project(":libraries:core-ui"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import arrow.core.Either
import arrow.core.right
import com.lexwilliam.branch.model.BranchPaymentMethod
import com.lexwilliam.branch.usecase.ObserveBranchUseCase
import com.lexwilliam.log.model.DataLog
import com.lexwilliam.log.model.LogSell
import com.lexwilliam.log.usecase.UpsertLogUseCase
import com.lexwilliam.order.checkout.navigation.CheckOutNavigationTarget
import com.lexwilliam.order.model.Order
import com.lexwilliam.order.usecase.DeleteOrderGroupUseCase
Expand All @@ -22,9 +19,6 @@ import com.lexwilliam.product.model.ProductCategory
import com.lexwilliam.product.model.ProductItem
import com.lexwilliam.product.usecase.ObserveProductCategoryUseCase
import com.lexwilliam.product.usecase.UpsertProductCategoryUseCase
import com.lexwilliam.transaction.model.Payment
import com.lexwilliam.transaction.model.PaymentMethod
import com.lexwilliam.transaction.model.PaymentMethodFee
import com.lexwilliam.transaction.model.Transaction
import com.lexwilliam.transaction.model.TransactionFee
import com.lexwilliam.transaction.usecase.UpsertTransactionUseCase
Expand Down Expand Up @@ -60,7 +54,6 @@ class CheckOutViewModel
private val observeProductCategory: ObserveProductCategoryUseCase,
private val upsertProductCategory: UpsertProductCategoryUseCase,
private val fetchUser: FetchUserUseCase,
private val upsertLog: UpsertLogUseCase,
observeSession: ObserveSessionUseCase,
observeBranch: ObserveBranchUseCase,
savedStateHandle: SavedStateHandle
Expand Down Expand Up @@ -172,50 +165,26 @@ class CheckOutViewModel
viewModelScope.launch {
val orderGroup = orderGroup.firstOrNull() ?: return@launch
val branchUUID = branchUUID.firstOrNull() ?: return@launch
val selectedPayMethod = _selectedPayMethod.value ?: return@launch
val user = user.firstOrNull() ?: return@launch
val categories = categories.firstOrNull() ?: return@launch
val orders = _orders.value
val paymentMethod =
PaymentMethod(
uuid = selectedPayMethod.uuid,
group = selectedPayMethod.group,
name = selectedPayMethod.name,
fee =
PaymentMethodFee(
fixed = selectedPayMethod.fee?.fixed ?: 0.0,
percent = selectedPayMethod.fee?.percent ?: 0.0f
)
)
val payment =
Payment(
uuid = UUID.randomUUID(),
total = orderGroup.totalPrice,
paymentMethod = paymentMethod,
createdAt = Clock.System.now()
)
val transactionUUID = UUID.randomUUID()
val soldItemsWithProfit =
decreaseProductItemQuantity(
orders = orders,
categories = categories
)
val transaction =
Transaction(
uuid = transactionUUID,
branchUUID = branchUUID,
orderGroup = orderGroup.copy(orders = orders),
payments = listOf(payment),
refunds = listOf(),
customer = "",
fee = _transactionFee.value,
// TODO: Implement Tip Later
tip = 0.0,
profit = soldItemsWithProfit.second,
createdBy = user.name,
createdAt = Clock.System.now()
)

val soldItemsWithProfit =
decreaseProductItemQuantity(
orders = orders,
categories = categories
)

when (val resultTransaction = upsertTransaction(transaction)) {
is Either.Left -> {
Log.d("TAG", resultTransaction.value.toString())
Expand All @@ -226,21 +195,6 @@ class CheckOutViewModel
Log.d("TAG", result.value.toString())
}
is Either.Right -> {
upsertLog(
log =
DataLog(
uuid = UUID.randomUUID(),
branchUUID = branchUUID,
sell =
LogSell(
uuid = UUID.randomUUID(),
orderGroup = orderGroup,
soldProducts = soldItemsWithProfit.first,
totalProfit = soldItemsWithProfit.second
),
createdAt = Clock.System.now()
)
)
_navigation
.send(
CheckOutNavigationTarget.TransactionDetail(transactionUUID)
Expand Down
1 change: 0 additions & 1 deletion feature/product/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ ktlint {
dependencies {
implementation(project(":data:product"))
implementation(project(":data:user"))
implementation(project(":data:log"))
implementation(project(":feature:barcode"))
implementation(project(":feature:category"))
implementation(project(":libraries:core"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.lexwilliam.core.extensions.addOrUpdateDuplicate
import com.lexwilliam.log.model.DataLog
import com.lexwilliam.log.model.LogDelete
import com.lexwilliam.log.model.LogRestock
import com.lexwilliam.log.usecase.UpsertLogUseCase
import com.lexwilliam.product.model.Product
import com.lexwilliam.product.model.ProductItem
import com.lexwilliam.product.navigation.ProductDetailNavigationTarget
Expand All @@ -36,7 +32,6 @@ import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.datetime.Clock
import java.util.UUID
import javax.inject.Inject

@OptIn(ExperimentalCoroutinesApi::class)
Expand All @@ -47,7 +42,6 @@ class ProductDetailViewModel
constructor(
observeProductCategory: ObserveProductCategoryUseCase,
private val upsertProductCategory: UpsertProductCategoryUseCase,
private val upsertLog: UpsertLogUseCase,
observeSession: ObserveSessionUseCase,
fetchUser: FetchUserUseCase,
savedStateHandle: SavedStateHandle
Expand Down Expand Up @@ -132,18 +126,6 @@ class ProductDetailViewModel
Log.d("TAG", failure.toString())
},
ifRight = {
upsertLog(
DataLog(
uuid = UUID.randomUUID(),
branchUUID = branchUUID,
delete =
LogDelete(
uuid = UUID.randomUUID(),
product = product.value
),
createdAt = Clock.System.now()
)
)
_navigation.send(ProductDetailNavigationTarget.BackStack)
}
)
Expand Down Expand Up @@ -213,23 +195,6 @@ class ProductDetailViewModel
Log.d("TAG", failure.toString())
},
ifRight = {
upsertLog(
log =
DataLog(
uuid = UUID.randomUUID(),
branchUUID = branchUUID,
restock =
LogRestock(
uuid = UUID.randomUUID(),
productUUID = product.uuid,
name = product.name,
originalStock = product.quantity,
addedStock = productItem.quantity,
price = productItem.buyPrice
),
createdAt = Clock.System.now()
)
)
_dialogState.update { null }
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ import com.lexwilliam.core.extensions.addOrUpdateDuplicate
import com.lexwilliam.core.extensions.isFirebaseUri
import com.lexwilliam.core.model.UploadImageFormat
import com.lexwilliam.inventory.scan.ProductScanEvent
import com.lexwilliam.log.model.DataLog
import com.lexwilliam.log.model.LogAdd
import com.lexwilliam.log.usecase.UpsertLogUseCase
import com.lexwilliam.product.category.CategoryUiEvent
import com.lexwilliam.product.category.CategoryUiState
import com.lexwilliam.product.model.Product
Expand Down Expand Up @@ -68,7 +65,6 @@ class ProductFormViewModel
private val uploadProductCategoryImage: UploadProductCategoryUseCase,
private val barcodeImageAnalyzer: BarcodeImageAnalyzer,
private val barcodeResultBoundaryAnalyzer: BarcodeResultBoundaryAnalyzer,
private val upsertLog: UpsertLogUseCase,
observeSession: ObserveSessionUseCase,
fetchUser: FetchUserUseCase,
savedStateHandle: SavedStateHandle
Expand Down Expand Up @@ -383,18 +379,6 @@ class ProductFormViewModel
_state.update { old -> old.copy(isLoading = false) }
},
ifRight = {
upsertLog(
DataLog(
uuid = UUID.randomUUID(),
branchUUID = branchUUID,
add =
LogAdd(
uuid = UUID.randomUUID(),
product = product
),
createdAt = Clock.System.now()
)
)
_state.update { old -> old.copy(isLoading = false) }
_navigation.send(ProductFormNavigationTarget.BackStack)
}
Expand Down
1 change: 0 additions & 1 deletion feature/transaction/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ ktlint {

dependencies {
implementation(project(":data:transaction"))
implementation(project(":data:log"))
implementation(project(":data:user"))
implementation(project(":libraries:core"))
implementation(project(":libraries:core-ui"))
Expand Down
2 changes: 0 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,4 @@ include(":data:transaction")
include(":domain:transaction")
include(":feature:transaction")
include(":libraries:db")
include(":data:log")
include(":domain:log")
include(":feature:profile")

0 comments on commit 070bf13

Please sign in to comment.