Фух, ну вроде добавил все перменные, что хотел. Осталось мб сделать "назначение админа", добавить в отчет "текущую дату" и в название может это + дополнить норм данными остаток, а ну еще и придумать с bikeid

This commit is contained in:
Кашин Максим 2023-12-26 15:41:35 +04:00
parent a985333daf
commit 529af56d53
28 changed files with 79 additions and 24 deletions

View File

@ -55,6 +55,7 @@ class RestBikeRepository(
x.dateTime,
x.weight,
x.radius,
x.colorbike,
x.maxCount - service.getRents().flatMap { rent ->
rent.items.filter { item -> item.id == x.id }
}.sumOf { item -> item.count },

View File

@ -12,6 +12,7 @@ class ItemFromBikeRemote(
val dateTime: LocalDateTime = LocalDateTime.MIN,
val weight: Double = 0.0,
val radius: Double = 0.0,
val colorbike: String = "",
val maxCount: Int = 0,
val availableCount: Int = 0,
val bikeId: Int = 0,
@ -22,6 +23,7 @@ fun ItemFromBikeRemote.toItemFromBike(): ItemFromBike = ItemFromBike(
dateTime,
weight,
radius,
colorbike,
availableCount,
bikeId
)
@ -31,6 +33,7 @@ fun ItemFromBike.toItemFromBikeRemote(): ItemFromBikeRemote = ItemFromBikeRemote
dateTime,
weight,
radius,
colorbike,
availableCount,
bikeId
)

View File

@ -13,7 +13,7 @@ class ItemFromCartRemote(
var bikeId: Int = 0,
)
fun ItemFromCartRemote.toItemFromCart(bike: BikeRemote, dateTime: LocalDateTime, weight: Double, radius: Double, availableCount: Int): ItemFromCart =
fun ItemFromCartRemote.toItemFromCart(bike: BikeRemote, dateTime: LocalDateTime, weight: Double, radius: Double, colorbike : String, availableCount: Int): ItemFromCart =
ItemFromCart(
id, dateTime, weight, radius, availableCount, count, bike.id, bike.toBike()
id, dateTime, weight, radius, colorbike, availableCount, count, bike.id, bike.toBike()
)

View File

@ -13,11 +13,12 @@ class ItemFromRentRemote(
@Contextual val dateTime: LocalDateTime = LocalDateTime.MIN,
val frozenWeight: Double = 0.0,
val radius: Double = 0.0,
val colorbike: String = "",
val count: Int = 0,
val bikeId: Int = 0,
)
fun ItemFromRentRemote.toItemFromRent(bike: BikeRemote): ItemFromRent =
ItemFromRent(
id, dateTime, frozenWeight, radius, count, bikeId, bike.toBike()
id, dateTime, frozenWeight, radius,colorbike, count, bikeId, bike.toBike()
)

View File

@ -12,6 +12,7 @@ data class ItemRemote(
val dateTime: LocalDateTime,
val weight: Double,
val radius: Double,
val colorbike: String,
val maxCount: Int,
val bikeId: Int = 0
)
@ -21,6 +22,7 @@ fun ItemRemote.toItem(): Item = Item(
dateTime,
weight,
radius,
colorbike,
maxCount,
bikeId
)
@ -30,6 +32,7 @@ fun Item.toItemRemote(): ItemRemote = ItemRemote(
dateTime,
weight,
radius,
colorbike,
maxCount,
bikeId
)

View File

@ -13,6 +13,7 @@ data class ItemWithBikeRemote(
val dateTime: LocalDateTime,
val weight: Double,
val radius: Double,
val colorbike: String,
val maxCount: Int,
val bikeId: Int = 0,
val bike: BikeRemote,
@ -23,6 +24,7 @@ fun ItemWithBikeRemote.toItem(): Item = Item(
dateTime,
weight,
radius,
colorbike,
maxCount,
bikeId
)

View File

@ -114,10 +114,10 @@ class RestItemRepository(
// Отображаем данные в виде таблицы
val tableStartY = yTitle + 80f
val columnWidths = floatArrayOf(0.5f, 1.5f, 1f, 0.5f, 1.5f, 1f) // Увеличиваем ширину столбцов
val columnWidths = floatArrayOf(0.5f, 1f, 0.6f, 0.5f, 1f, 1f, 1f) // Увеличиваем ширину столбцов
val rowHeight = 30f // Увеличиваем высоту строки
drawTableRow(canvas, arrayOf("ID", "Дата проверки", "Вес", "R", "Количество", "ID велосипеда"), columnWidths, tableStartY, paint)
drawTableRow(canvas, arrayOf("ID", "Дата", "Вес", "R", "Цвет", "Кол-во", "ID велосипеда"), columnWidths, tableStartY, paint)
for ((index, report) in reportData.withIndex()) {
val row = arrayOf(
@ -125,6 +125,7 @@ class RestItemRepository(
report.dateTime.toString(),
report.weight.toString(),
report.radius.toString(),
report.colorbike.toString(),
report.maxCount.toString(),
report.bikeId.toString()
)

View File

@ -60,6 +60,7 @@ class RestRentRepository(
it.id,
it.frozenWeight,
it.radius,
it.colorbike,
it.count
)
)

View File

@ -20,6 +20,7 @@ class RestRentItemRepository(
item.dateTime,
item.weight,
item.radius,
item.colorbike,
rentItemCrossRef.count,
item.bikeId
)

View File

@ -8,6 +8,7 @@ data class ReportRemote(
val dateTime: Int = 0,
val weight: Double = 0.0,
val radius: Double = 0.0,
val colorbike: String = "",
val maxCount: Int = 0,
val bikeId: Int = 0
)

View File

@ -54,6 +54,7 @@ class RestUserRepository(
item.dateTime,
item.weight,
item.radius,
item.colorbike,
item.maxCount - service.getRents().flatMap { rent ->
rent.items.filter { item -> item.id == it.id }
}.sumOf { item -> item.count })

View File

@ -94,6 +94,7 @@ fun Cart(
dateTime = item.dateTime,
weight = item.weight,
radius = item.radius,
colorbike = item.colorbike,
maxCount = 0,
bikeId = item.bikeId
), user = it
@ -110,6 +111,7 @@ fun Cart(
dateTime = item.dateTime,
weight = item.weight,
radius = item.radius,
colorbike = item.colorbike,
maxCount = 0,
bikeId = item.bikeId
), userId = it, count = count, availableCount = item.availableCount
@ -266,6 +268,7 @@ private fun ItemListItem(
text = "${item.bike.name}\n" +
"Вес: ${item.weight}\n" +
"R: ${item.radius}\n" +
"Цвет: ${item.colorbike}\n" +
"${currentCount}/${item.availableCount}\n" +
"Год: ${formattedDate}",
color = MaterialTheme.colorScheme.onSecondary

View File

@ -41,6 +41,7 @@ class CartViewModel(
item.uid,
item.weight,
item.radius,
item.colorbike,
item.count
)
)

View File

@ -109,7 +109,7 @@ fun ItemList(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
text = "Вес: ${item.weight}\n" + "R: ${item.radius}\n" + "Количество: ${item.availableCount}\n" + "Год: ${formattedDate}",
text = "Вес: ${item.weight}\n" + "R: ${item.radius}\n" + "Цвет: ${item.colorbike}\n" + "Количество: ${item.availableCount}\n" + "Год: ${formattedDate}",
color = MaterialTheme.colorScheme.onPrimary
)
}

View File

@ -18,6 +18,7 @@ class ItemListViewModel(
dateTime = item.dateTime,
weight = item.weight,
radius = item.radius,
colorbike = item.colorbike,
maxCount = 0,
bikeId = 0
)

View File

@ -90,6 +90,7 @@ fun RentView(
text = "${item.bike.name}\n" +
"Вес: ${item.frozenWeight}\n" +
"R: ${item.radius}\n" +
"Цвет: ${item.colorbike}\n" +
"Количество: ${count.value}\n" +
"Дата: ${formattedDate}",
color = MaterialTheme.colorScheme.onPrimary

View File

@ -300,17 +300,18 @@ fun TableScreen(reportData: List<ReportRemote>) {
.fillMaxWidth(), // Занимаем максимальную ширину
verticalAlignment = Alignment.CenterVertically // Выравниваем по центру вертикали
) {
Text("ID", Modifier.weight(0.5f), color = MaterialTheme.colorScheme.background)
Text("Дата", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background)
Text("Вес", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background)
Text("R", Modifier.weight(0.5f), color = MaterialTheme.colorScheme.background)
Text("ID", Modifier.weight(0.3f), color = MaterialTheme.colorScheme.background)
Text("Дата", Modifier.weight(0.8f), color = MaterialTheme.colorScheme.background)
Text("Вес", Modifier.weight(0.7f), color = MaterialTheme.colorScheme.background)
Text("R", Modifier.weight(0.6f), color = MaterialTheme.colorScheme.background)
Text("Цвет", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background)
Text("Кол-во", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background)
Text("ID вел.", Modifier.weight(1.0f), color = MaterialTheme.colorScheme.background)
Text("ID вел", Modifier.weight(0.5f), color = MaterialTheme.colorScheme.background)
}
// Here are all the lines of your table.
reportData.forEach {
val (id, dateTime, weight, radius, maxCount, bikeId) = it
val (id, dateTime, weight, radius,colorbike, maxCount, bikeId) = it
Card(
modifier = Modifier
.fillMaxWidth()
@ -319,12 +320,13 @@ fun TableScreen(reportData: List<ReportRemote>) {
Row(Modifier
.fillMaxWidth()
.background(MaterialTheme.colorScheme.background)) {
Text(id.toString(), Modifier.weight(0.5f))
Text(dateTime.toString(), Modifier.weight(1.0f))
Text(weight.toString(), Modifier.weight(1.0f))
Text(radius.toString(), Modifier.weight(1.0f))
Text(id.toString(), Modifier.weight(0.3f))
Text(dateTime.toString(), Modifier.weight(0.8f))
Text(weight.toString(), Modifier.weight(0.7f))
Text(radius.toString(), Modifier.weight(0.6f))
Text(colorbike.toString(), Modifier.weight(1.0f))
Text(maxCount.toString(), Modifier.weight(1.0f))
Text(bikeId.toString(), Modifier.weight(1.0f))
Text(bikeId.toString(), Modifier.weight(0.5f))
}
}
}

View File

@ -1,5 +1,6 @@
package com.example.myapplication.database.entities.composeui.edit
import android.annotation.SuppressLint
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
@ -53,6 +54,7 @@ fun Long.toLocalDate(): org.threeten.bp.LocalDate {
return instant.atZone(ZoneId.systemDefault()).toLocalDate()
}
@SuppressLint("SuspiciousIndentation")
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun ItemEdit(
@ -140,6 +142,19 @@ private fun ItemEdit(
)
)
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = itemUiState.itemDetails.colorbike,
label = { Text(text = "Цвет") },
onValueChange = {
onUpdate(itemUiState.itemDetails.copy(colorbike = it))
},
keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Text),
textStyle = MaterialTheme.typography.bodyLarge.copy(
color = MaterialTheme.colorScheme.onSecondary
)
)
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = itemUiState.itemDetails.maxCount.toString(),

View File

@ -81,6 +81,7 @@ data class ItemDetails(
val dateTime: LocalDateTime = LocalDateTime.MIN,
val weight: String = "0",
val radius: String = "0",
val colorbike: String = "0",
val maxCount: Int = 0,
val bikeId: Int = 0
)
@ -90,6 +91,7 @@ fun ItemDetails.toItem(uid: Int = 0, bikeUid: Int = 0): Item = Item(
dateTime = dateTime,
weight = weight.toDoubleOrNull() ?: 0.0,
radius = radius.toDoubleOrNull() ?: 0.0,
colorbike = colorbike,
maxCount = maxCount,
bikeId = bikeUid
)
@ -99,6 +101,7 @@ fun Item.toDetails(): ItemDetails = ItemDetails(
dateTime = dateTime,
weight = weight.toString(),
radius = radius.toString(),
colorbike = colorbike,
maxCount = maxCount,
bikeId = bikeId
)

View File

@ -16,7 +16,7 @@ interface BikeDao {
fun getAll(): PagingSource<Int, Bike>
@Query(
"SELECT c.*, s.uid as item_uid, s.date_time, s.weight, s.radius, s.max_count-IFNULL(SUM(os.count), 0) as available_count, c.uid as bike_id " +
"SELECT c.*, s.uid as item_uid, s.date_time, s.weight, s.radius,s.colorbike, s.max_count-IFNULL(SUM(os.count), 0) as available_count, c.uid as bike_id " +
"FROM bikes AS c " +
"LEFT JOIN items AS s ON s.bike_id = c.uid " +
"LEFT JOIN rents_items AS os ON os.item_id = s.uid " +

View File

@ -15,7 +15,7 @@ interface RentDao {
fun getAll(userId: Int?): PagingSource<Int, Rent>
@Query(
"SELECT o.*, s.*, os.count, os.frozen_weight, os.radius " +
"SELECT o.*, s.*, os.count, os.frozen_weight, os.radius, os.colorbike " +
"FROM rents AS o " +
"JOIN rents_items AS os ON os.rent_id = o.uid " +
"JOIN items AS s ON s.uid = os.item_id " +

View File

@ -25,6 +25,7 @@ data class Item(
val dateTime: LocalDateTime,
val weight: Double,
val radius: Double,
val colorbike: String,
@ColumnInfo(name = "max_count")
val maxCount: Int,
@ColumnInfo(name = "bike_id", index = true)
@ -35,9 +36,10 @@ data class Item(
dateTime: LocalDateTime,
weight: Double,
radius: Double,
colorbike: String,
maxCount: Int,
bike: Bike,
) : this(0, dateTime, weight,radius, maxCount, bike.uid)
) : this(0, dateTime, weight,radius,colorbike, maxCount, bike.uid)
companion object {
fun getItem(index: Int = 0): Item {
@ -46,6 +48,7 @@ data class Item(
LocalDateTime.MIN,
0.0,
0.0,
"",
0,
0
)
@ -60,6 +63,7 @@ data class Item(
if (dateTime != other.dateTime) return false
if (weight != other.weight) return false
if (radius != other.radius) return false
if (colorbike != other.colorbike) return false
if (maxCount != other.maxCount) return false
if (bikeId != other.bikeId) return false
return true
@ -70,6 +74,7 @@ data class Item(
result = 31 * result + dateTime.hashCode()
result = 31 * result + weight.hashCode()
result = 31 * result + radius.hashCode()
result = 31 * result + colorbike.hashCode()
result = 31 * result + maxCount.hashCode()
result = 31 * result + bikeId.hashCode()
return result

View File

@ -11,6 +11,7 @@ data class ItemFromBike(
val dateTime: LocalDateTime,
val weight: Double,
val radius: Double,
val colorbike: String,
@ColumnInfo(name = "available_count")
var availableCount: Int,
@ColumnInfo(name = "bike_id")
@ -25,6 +26,7 @@ data class ItemFromBike(
if (dateFormatter.format(dateTime) != dateFormatter.format(other.dateTime)) return false
if (weight != other.weight) return false
if (radius != other.radius) return false
if (colorbike != other.colorbike) return false
if (availableCount != other.availableCount) return false
if (bikeId != other.bikeId) return false
return true
@ -35,6 +37,7 @@ data class ItemFromBike(
result = 31 * result + dateTime.hashCode()
result = 31 * result + weight.hashCode()
result = 31 * result + radius.hashCode()
result = 31 * result + colorbike.hashCode()
result = 31 * result + availableCount.hashCode()
result = 31 * result + bikeId.hashCode()
return result
@ -46,6 +49,7 @@ fun ItemFromBike.toItem(): Item = Item (
dateTime,
weight,
radius,
colorbike,
availableCount,
bikeId
)

View File

@ -11,6 +11,7 @@ data class ItemFromCart(
val dateTime: LocalDateTime,
val weight: Double,
val radius: Double,
val colorbike: String,
@ColumnInfo(name = "available_count")
val availableCount: Int,
val count: Int,

View File

@ -12,6 +12,7 @@ data class ItemFromRent(
@ColumnInfo(name = "frozen_weight")
val frozenWeight: Double,
val radius: Double,
val colorbike: String,
val count: Int,
@ColumnInfo(name = "bike_id")
val bikeId: Int = 0,

View File

@ -16,6 +16,7 @@ data class RentItemCrossRef(
@ColumnInfo(name = "frozen_weight")
val frozenWeight: Double,
val radius: Double,
val colorbike: String,
val count: Int
) {
override fun equals(other: Any?): Boolean {

View File

@ -16,10 +16,11 @@
"rents": [],
"items": [
{
"dateTime": 2020,
"weight": 23.6,
"radius": 14,
"maxCount": 5,
"dateTime": 2009,
"weight": 36.6,
"radius": 14.5,
"colorbike": "Красный",
"maxCount": 10,
"bikeId": 3,
"id": 1
}

View File

@ -40,6 +40,7 @@ function generateReport(items) {
dateTime: item.dateTime,
weight: item.weight,
radius: item.radius,
colorbike: item.colorbike,
maxCount: item.maxCount,
bikeId: item.bikeId