исправления отчета. надо проверить работоспособность
This commit is contained in:
parent
4b84248c66
commit
01bc335c4f
@ -157,7 +157,7 @@ interface MyServerService {
|
|||||||
suspend fun getReport(
|
suspend fun getReport(
|
||||||
@Query("startDate") startDate: Date,
|
@Query("startDate") startDate: Date,
|
||||||
@Query("endDate") endDate: Date
|
@Query("endDate") endDate: Date
|
||||||
): List<ReportRemote>
|
): ReportRemote
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
//private const val BASE_URL = "http://192.168.154.166:8080/"
|
//private const val BASE_URL = "http://192.168.154.166:8080/"
|
||||||
|
@ -1,21 +1,14 @@
|
|||||||
package com.example.myapplication.api.session
|
package com.example.myapplication.api.session
|
||||||
|
|
||||||
import kotlinx.serialization.Contextual
|
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ReportRemote(
|
data class ReportRemote(
|
||||||
@SerialName("cinema_name")
|
@SerialName("report_data")
|
||||||
val cinemaName: String = "",
|
val reportData: List<SessionFromReportRemote>,
|
||||||
@Contextual
|
@SerialName("total_revenue")
|
||||||
@SerialName("current_ticket_date_time")
|
val totalRevenue: Double = 0.0,
|
||||||
val ticketDateTime: org.threeten.bp.LocalDateTime,
|
@SerialName("total_purchased_tickets")
|
||||||
@SerialName("current_ticket_price")
|
val totalPurchasedTickets: Int = 0
|
||||||
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
|
|
||||||
)
|
)
|
||||||
|
@ -51,7 +51,7 @@ class RestSessionRepository(
|
|||||||
dbSessionRepository.deleteSession(session)
|
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)
|
return service.getReport(startDate, endDate)
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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
|
||||||
|
)
|
@ -101,7 +101,7 @@ fun Cart(
|
|||||||
ApiStatus.LOADING -> LoadingPlaceholder()
|
ApiStatus.LOADING -> LoadingPlaceholder()
|
||||||
else -> ErrorPlaceholder(
|
else -> ErrorPlaceholder(
|
||||||
message = viewModel.apiError,
|
message = viewModel.apiError,
|
||||||
onBack = { navController.navigate(Screen.Report.route) }
|
onBack = { navController.navigate(Screen.Cart.route) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ fun Report(
|
|||||||
Text(text = "Получить отчет")
|
Text(text = "Получить отчет")
|
||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
CardScreen(reportData = viewModel.reportResultUiState.report)
|
CardScreen(report = viewModel.reportResultUiState.report)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,14 +108,15 @@ fun Report(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CardScreen(reportData: List<ReportRemote>) {
|
fun CardScreen(report: ReportRemote?) {
|
||||||
|
if (report == null) return
|
||||||
val dateFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")
|
val dateFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")
|
||||||
reportData.forEach {
|
report.reportData.forEach {
|
||||||
val (cinemaName, ticketDateTime, ticketPrice, ticketQuantity, ticketsPurchased, revenue) = it
|
val (cinemaName, ticketDateTime, ticketPrice, ticketQuantity, ticketsPurchased, revenue) = it
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.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(
|
Column(
|
||||||
Modifier
|
Modifier
|
||||||
@ -132,4 +133,20 @@ fun CardScreen(reportData: List<ReportRemote>) {
|
|||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
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))
|
||||||
}
|
}
|
||||||
|
@ -57,5 +57,5 @@ data class ReportUiState(
|
|||||||
)
|
)
|
||||||
|
|
||||||
data class ReportResultUiState(
|
data class ReportResultUiState(
|
||||||
val report: List<ReportRemote> = emptyList()
|
val report: ReportRemote? = null
|
||||||
)
|
)
|
@ -54,8 +54,10 @@ module.exports = (req, res, next) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const sortedReportData = reportData.sort((a, b) => b.revenue - a.revenue);
|
const sortedReportData = reportData.sort((a, b) => b.revenue - a.revenue);
|
||||||
|
const report = { "sortedReportData": sortedReportData,
|
||||||
res.json(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) {
|
} catch (error) {
|
||||||
console.error('Error processing report: ', error);
|
console.error('Error processing report: ', error);
|
||||||
res.status(500).json({ message: 'Internal Server Error' });
|
res.status(500).json({ message: 'Internal Server Error' });
|
||||||
|
Loading…
Reference in New Issue
Block a user