Skip to content

Commit

Permalink
feat: Add Sale to invoice
Browse files Browse the repository at this point in the history
Add sale and edit enabled
  • Loading branch information
EndikaCo committed Feb 15, 2024
1 parent d2ff41b commit 46ab51b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.endcodev.myinvoice.domain.models.common.FilterModel
@Composable
fun FiltersView(onFiltersChanged: (List<FilterModel>) -> Unit, filters: List<FilterModel>) {


LazyRow(Modifier.fillMaxWidth()) {
items(filters) {
FilterItem(it, onFilterClick = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
Expand Down Expand Up @@ -42,6 +46,8 @@ fun ProductDialog(
onDismissRequest = { onDialogCancel() },
properties = DialogProperties(dismissOnBackPress = true, dismissOnClickOutside = true)
) {
var price by remember { mutableFloatStateOf(sale.price) }
var quantity by remember { mutableFloatStateOf(sale.quantity) }

var colorFilter: ColorFilter? = null
var image = uriToPainterImage(sale.product.image)
Expand Down Expand Up @@ -74,24 +80,26 @@ fun ProductDialog(
modifier = Modifier
.padding(start = 8.dp, end = 8.dp, top = 5.dp, bottom = 5.dp)
) {

ItemCost(
label = "price",
amount = sale.price,
onAmountChanged = {}
label = "Quantity",
amount = quantity,
onAmountChanged = { newQuantity ->
quantity = newQuantity
}
)
Spacer(modifier = Modifier.width(4.dp))
ItemCost(
label = "Quantity",
amount = sale.quantity,
onAmountChanged = {}
label = "price",
amount = price,
onAmountChanged = { newPrice -> price = newPrice }
)
Spacer(modifier = Modifier.width(4.dp))
ItemCost(
label = "Total",
amount = sale.quantity * sale.price,
onAmountChanged = {}
)

}
Row(
horizontalArrangement = Arrangement.SpaceBetween,
Expand All @@ -102,7 +110,14 @@ fun ProductDialog(
Button(onClick = { onDialogCancel() }) {
Text(text = "Cancel")
}
Button(onClick = { }) {
Button(onClick = {
onDialogAccept(
sale.copy(
price = price,
quantity = quantity
)
)
}) {
Text(text = "Accept")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import com.endcodev.myinvoice.presentation.compose.components.filteredImage
import com.endcodev.myinvoice.presentation.compose.dialogs.ChooseCustomerDialogActions
import com.endcodev.myinvoice.presentation.compose.dialogs.InvoiceProductAddDialogActions
import com.endcodev.myinvoice.presentation.compose.dialogs.ProductDialog
import com.endcodev.myinvoice.presentation.compose.screens.details.MyObject.NULL_ITEM
import com.endcodev.myinvoice.presentation.navigation.Routes
import com.endcodev.myinvoice.presentation.theme.MyInvoiceTheme
import com.endcodev.myinvoice.presentation.viewmodels.InvoiceInfoViewModel
Expand All @@ -74,6 +75,10 @@ import java.time.LocalDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter

object MyObject {
const val NULL_ITEM = -1
}

@Composable
fun InvoiceDetailActions(
invoiceId: String?,
Expand Down Expand Up @@ -117,11 +122,12 @@ fun InvoiceInfoScreen(
onSwipeDelete: (SaleItem) -> Unit
) {


val state = rememberDatePickerState()
val dateDialog = remember { mutableStateOf(false) } //show DatePicker dialog
val customerDialog = remember { mutableStateOf(false) } //show CustomerSelect dialog
val productDialog = remember { mutableIntStateOf(-1) }
val priceDialog = remember { mutableStateOf(false) }
val priceDialog = remember { mutableIntStateOf(-1) }

if (dateDialog.value)
MyDatePicker(
Expand All @@ -135,7 +141,8 @@ fun InvoiceInfoScreen(
}
)

if (productDialog.intValue != -1) {

if (productDialog.intValue != NULL_ITEM) {
InvoiceProductAddDialogActions(
onDialogAccept = { product ->
onSaleChanged(
Expand All @@ -155,27 +162,16 @@ fun InvoiceInfoScreen(
)
}

if (priceDialog.value)
if (priceDialog.intValue != -1)
ProductDialog(
sale = SaleItem(
id = 1,
product = Product(
null,
"PRO-3121",
"233",
"das",
"",
12.00F,
12.00F,
12.00F,

),
31F,
quantity = 12F,
discount = 10
),
onDialogAccept = {}, //todo
onDialogCancel = { priceDialog.value = false },
sale = uiState.invoice.saleList[priceDialog.intValue],
onDialogAccept = {
onSaleChanged(it)
priceDialog.intValue = NULL_ITEM
},
onDialogCancel = {
priceDialog.intValue = NULL_ITEM
},
)

if (customerDialog.value)
Expand All @@ -196,7 +192,7 @@ fun InvoiceInfoScreen(
onCustomerClick = { customerDialog.value = true },
uiState = uiState,
onProductClick = { productDialog.intValue = it },
onPricesClick = { priceDialog.value = true },
onPricesClick = { priceDialog.intValue = it },
onSwipeDelete = onSwipeDelete
)
},
Expand Down Expand Up @@ -231,7 +227,7 @@ fun InvoiceInfoContent(
onCustomerClick: () -> Unit,
uiState: InvoiceUiState,
onProductClick: (Int) -> Unit,
onPricesClick: () -> Unit,
onPricesClick: (Int) -> Unit,
onSwipeDelete: (SaleItem) -> Unit
) {
Column(
Expand Down Expand Up @@ -261,7 +257,7 @@ fun InvoiceInfoContent(
fun InvoiceItemsList(
salesList: List<SaleItem>,
onProductClick: (Int) -> Unit,
onPricesClick: () -> Unit,
onPricesClick: (Int) -> Unit,
onSwipeDelete: (SaleItem) -> Unit
) {
LazyColumn(horizontalAlignment = Alignment.CenterHorizontally,
Expand All @@ -276,10 +272,10 @@ fun InvoiceItemsList(
) {
InvoiceProduct2(
onProductClick = {
onProductClick(index + 1)
onProductClick(index)
},
onPricesClick = {
onPricesClick()
onPricesClick(index)
},
sale
)
Expand Down

0 comments on commit 46ab51b

Please sign in to comment.