исправления отчета. надо проверить работоспособность

This commit is contained in:
dasha 2023-12-21 14:39:16 +04:00
parent 4b84248c66
commit 01bc335c4f
8 changed files with 56 additions and 23 deletions

View File

@ -157,7 +157,7 @@ interface MyServerService {
suspend fun getReport(
@Query("startDate") startDate: Date,
@Query("endDate") endDate: Date
): List<ReportRemote>
): ReportRemote
companion object {
//private const val BASE_URL = "http://192.168.154.166:8080/"

View File

@ -1,21 +1,14 @@
package com.example.myapplication.api.session
import kotlinx.serialization.Contextual
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class ReportRemote(
@SerialName("cinema_name")
val cinemaName: String = "",
@Contextual
@SerialName("current_ticket_date_time")
val ticketDateTime: org.threeten.bp.LocalDateTime,
@SerialName("current_ticket_price")
val ticketPrice: Double = 0.0,
@SerialName("max_ticket_quantity")
val ticketQuantity: Int = 0,
@SerialName("purchased_tickets")
val ticketsPurchased: Int = 0,
val revenue: Double = 0.0
@SerialName("report_data")
val reportData: List<SessionFromReportRemote>,
@SerialName("total_revenue")
val totalRevenue: Double = 0.0,
@SerialName("total_purchased_tickets")
val totalPurchasedTickets: Int = 0
)

View File

@ -51,7 +51,7 @@ class RestSessionRepository(
dbSessionRepository.deleteSession(session)
}
suspend fun getReport(startDate: Date, endDate: Date): List<ReportRemote> {
suspend fun getReport(startDate: Date, endDate: Date): ReportRemote {
return service.getReport(startDate, endDate)
}
}

View File

@ -0,0 +1,21 @@
package com.example.myapplication.api.session
import kotlinx.serialization.Contextual
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class SessionFromReportRemote(
@SerialName("cinema_name")
val cinemaName: String = "",
@Contextual
@SerialName("current_ticket_date_time")
val ticketDateTime: org.threeten.bp.LocalDateTime,
@SerialName("current_ticket_price")
val ticketPrice: Double = 0.0,
@SerialName("max_ticket_quantity")
val ticketQuantity: Int = 0,
@SerialName("purchased_tickets")
val ticketsPurchased: Int = 0,
val revenue: Double = 0.0
)

View File

@ -101,7 +101,7 @@ fun Cart(
ApiStatus.LOADING -> LoadingPlaceholder()
else -> ErrorPlaceholder(
message = viewModel.apiError,
onBack = { navController.navigate(Screen.Report.route) }
onBack = { navController.navigate(Screen.Cart.route) }
)
}
}

View File

@ -95,7 +95,7 @@ fun Report(
Text(text = "Получить отчет")
}
Spacer(modifier = Modifier.height(16.dp))
CardScreen(reportData = viewModel.reportResultUiState.report)
CardScreen(report = viewModel.reportResultUiState.report)
}
}
@ -108,14 +108,15 @@ fun Report(
}
@Composable
fun CardScreen(reportData: List<ReportRemote>) {
fun CardScreen(report: ReportRemote?) {
if (report == null) return
val dateFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")
reportData.forEach {
report.reportData.forEach {
val (cinemaName, ticketDateTime, ticketPrice, ticketQuantity, ticketsPurchased, revenue) = it
Row(
modifier = Modifier
.fillMaxWidth()
.border(width = 1.dp, color = Color.White, shape = MaterialTheme.shapes.small)
.border(width = 1.dp, color = MaterialTheme.colorScheme.onBackground, shape = MaterialTheme.shapes.small)
) {
Column(
Modifier
@ -132,4 +133,20 @@ fun CardScreen(reportData: List<ReportRemote>) {
}
Spacer(modifier = Modifier.height(16.dp))
}
Text(text = "Итого: ")
Row(
modifier = Modifier
.fillMaxWidth()
.border(width = 1.dp, color = MaterialTheme.colorScheme.onBackground, shape = MaterialTheme.shapes.small)
) {
Column(
Modifier
.padding(16.dp)
.background(color = Color.Transparent)
) {
Text(text = "Купили: ${report.totalPurchasedTickets}")
Text(text = "Выручка: ${report.totalRevenue}")
}
}
Spacer(modifier = Modifier.height(16.dp))
}

View File

@ -57,5 +57,5 @@ data class ReportUiState(
)
data class ReportResultUiState(
val report: List<ReportRemote> = emptyList()
val report: ReportRemote? = null
)

View File

@ -54,8 +54,10 @@ module.exports = (req, res, next) => {
});
const sortedReportData = reportData.sort((a, b) => b.revenue - a.revenue);
res.json(sortedReportData);
const report = { "sortedReportData": sortedReportData,
"total_revenue": sortedReportData.reduce((a, b) => a + b.revenue, 0),
"total_purchased_tickets": sortedReportData.reduce((a, b) => a + b.purchased_tickets, 0) }
res.json(report);
} catch (error) {
console.error('Error processing report: ', error);
res.status(500).json({ message: 'Internal Server Error' });