|
|
|
|
@ -9,6 +9,10 @@ import SwiftUI |
|
|
|
|
|
|
|
|
|
struct CashierDetailView: View { |
|
|
|
|
var tournaments : [Tournament] |
|
|
|
|
@State private var calculateEarnings: Bool = false |
|
|
|
|
@State private var calculateCompletion: Bool = false |
|
|
|
|
@State private var earnings: Double? = nil |
|
|
|
|
@State private var paidCompletion: Double? = nil |
|
|
|
|
|
|
|
|
|
init(tournaments: [Tournament]) { |
|
|
|
|
self.tournaments = tournaments |
|
|
|
|
@ -20,6 +24,27 @@ struct CashierDetailView: View { |
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
List { |
|
|
|
|
if tournaments.count > 1 { |
|
|
|
|
Section { |
|
|
|
|
LabeledContent { |
|
|
|
|
if let earnings { |
|
|
|
|
Text(earnings.formatted(.currency(code: "EUR").precision(.fractionLength(0)))) |
|
|
|
|
} else { |
|
|
|
|
ProgressView() |
|
|
|
|
} |
|
|
|
|
} label: { |
|
|
|
|
Text("Encaissement") |
|
|
|
|
if let paidCompletion { |
|
|
|
|
Text(paidCompletion.formatted(.percent.precision(.fractionLength(0)))).foregroundStyle(.secondary) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
_tournamentsCashierDetailView(tournaments) |
|
|
|
|
|
|
|
|
|
} header: { |
|
|
|
|
Text("Bilan") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ForEach(tournaments) { tournament in |
|
|
|
|
Section { |
|
|
|
|
LabeledContent { |
|
|
|
|
@ -37,12 +62,29 @@ struct CashierDetailView: View { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.headerProminence(.increased) |
|
|
|
|
.onAppear { |
|
|
|
|
Task { |
|
|
|
|
_getEarnings() |
|
|
|
|
_getPaidCompletion() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _getEarnings() { |
|
|
|
|
earnings = tournaments.map { $0.earnings() }.reduce(0,+) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _getPaidCompletion() { |
|
|
|
|
let selectedPlayers = tournaments.flatMap { $0.selectedPlayers() } |
|
|
|
|
if selectedPlayers.isEmpty { paidCompletion = 0 } |
|
|
|
|
paidCompletion = Double(selectedPlayers.filter { $0.hasPaid() }.count) / Double(selectedPlayers.count) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _tournamentCashierDetailView(_ tournament: Tournament) -> some View { |
|
|
|
|
DisclosureGroup { |
|
|
|
|
let selectedPlayers = tournament.selectedPlayers() |
|
|
|
|
ForEach(PlayerRegistration.PlayerPaymentType.allCases) { type in |
|
|
|
|
let count = tournament.selectedPlayers().filter({ $0.paymentType == type }).count |
|
|
|
|
let count = selectedPlayers.filter({ $0.paymentType == type }).count |
|
|
|
|
if count > 0 { |
|
|
|
|
LabeledContent { |
|
|
|
|
if let entryFee = tournament.entryFee { |
|
|
|
|
@ -58,20 +100,22 @@ struct CashierDetailView: View { |
|
|
|
|
} label: { |
|
|
|
|
Text("Voir le détail") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// |
|
|
|
|
// Section { |
|
|
|
|
// ForEach(tournaments) { tournament in |
|
|
|
|
// } |
|
|
|
|
//// HStack { |
|
|
|
|
//// Text("Total") |
|
|
|
|
//// Spacer() |
|
|
|
|
//// Text(event.earnings.formatted(.currency(code: "EUR").precision(.fractionLength(0)))) |
|
|
|
|
//// Text(event.paidCompletion.formatted(.percent.precision(.fractionLength(0)))).foregroundStyle(.secondary) |
|
|
|
|
//// } |
|
|
|
|
// } header: { |
|
|
|
|
// Text("Encaissement") |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
private func _tournamentsCashierDetailView(_ tournaments: [Tournament]) -> some View { |
|
|
|
|
DisclosureGroup { |
|
|
|
|
ForEach(PlayerRegistration.PlayerPaymentType.allCases) { type in |
|
|
|
|
let value = tournaments.compactMap({ $0.paidSelectedPlayers(type: type) }).reduce(0,+) |
|
|
|
|
if value > 0 { |
|
|
|
|
LabeledContent { |
|
|
|
|
Text(value.formatted(.currency(code: "EUR"))) |
|
|
|
|
} label: { |
|
|
|
|
Text(type.localizedLabel()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} label: { |
|
|
|
|
Text("Voir le détail") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|