fix cashier

multistore
Razmig Sarkissian 1 year ago
parent eaafbdc248
commit 79871c3d5a
  1. 138
      PadelClub/Views/Cashier/CashierDetailView.swift

@ -9,8 +9,6 @@ import SwiftUI
struct CashierDetailView: View { struct CashierDetailView: View {
var tournaments : [Tournament] var tournaments : [Tournament]
@State private var calculateEarnings: Bool = false
@State private var calculateCompletion: Bool = false
@State private var earnings: Double? = nil @State private var earnings: Double? = nil
@State private var paidCompletion: Double? = nil @State private var paidCompletion: Double? = nil
@ -46,26 +44,19 @@ struct CashierDetailView: View {
} }
ForEach(tournaments) { tournament in ForEach(tournaments) { tournament in
Section { CashierSectionView(tournament: tournament, showTournamentTitle: tournaments.count > 1)
LabeledContent {
Text(tournament.earnings().formatted(.currency(code: "EUR").precision(.fractionLength(0))))
} label: {
Text("Encaissement")
Text(tournament.paidCompletion().formatted(.percent.precision(.fractionLength(0)))).foregroundStyle(.secondary)
}
_tournamentCashierDetailView(tournament)
} header: {
if tournaments.count > 1 {
Text(tournament.tournamentTitle())
}
}
} }
} }
.headerProminence(.increased) .headerProminence(.increased)
.onAppear { .onAppear {
Task { Task {
_getEarnings() if earnings == nil {
_getPaidCompletion() _getEarnings()
}
if paidCompletion == nil {
_getPaidCompletion()
}
} }
} }
} }
@ -80,42 +71,105 @@ struct CashierDetailView: View {
paidCompletion = Double(selectedPlayers.filter { $0.hasPaid() }.count) / Double(selectedPlayers.count) paidCompletion = Double(selectedPlayers.filter { $0.hasPaid() }.count) / Double(selectedPlayers.count)
} }
private func _tournamentCashierDetailView(_ tournament: Tournament) -> some View { private func _tournamentsCashierDetailView(_ tournaments: [Tournament]) -> some View {
DisclosureGroup { DisclosureGroup {
let selectedPlayers = tournament.selectedPlayers()
ForEach(PlayerRegistration.PlayerPaymentType.allCases) { type in ForEach(PlayerRegistration.PlayerPaymentType.allCases) { type in
let count = selectedPlayers.filter({ $0.paymentType == type }).count PaymentTypeCashierRowView(tournaments: tournaments, type: type)
if count > 0 {
LabeledContent {
if let entryFee = tournament.entryFee {
let sum = Double(count) * entryFee
Text(sum.formatted(.currency(code: "EUR")))
}
} label: {
Text(type.localizedLabel())
Text(count.formatted())
}
}
} }
} label: { } label: {
Text("Voir le détail") Text("Voir le détail")
} }
} }
private func _tournamentsCashierDetailView(_ tournaments: [Tournament]) -> some View { struct CashierSectionView: View {
DisclosureGroup { let tournament: Tournament
ForEach(PlayerRegistration.PlayerPaymentType.allCases) { type in let showTournamentTitle: Bool
let value = tournaments.compactMap({ $0.paidSelectedPlayers(type: type) }).reduce(0,+) @State private var earnings: Double? = nil
if value > 0 { @State private var paidCompletion: Double? = nil
LabeledContent {
Text(value.formatted(.currency(code: "EUR"))) var body: some View {
} label: { Section {
Text(type.localizedLabel()) 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)
}
}
CashierDetailDisclosureView(tournament: tournament)
} header: {
if showTournamentTitle {
Text(tournament.tournamentTitle())
}
}
.onAppear {
Task {
if earnings == nil {
earnings = tournament.earnings()
}
if paidCompletion == nil {
paidCompletion = tournament.paidCompletion()
} }
} }
} }
} label: { }
Text("Voir le détail") }
struct PaymentTypeCashierRowView: View {
let tournaments: [Tournament]
let type: PlayerRegistration.PlayerPaymentType
@State private var value: Double?
var body: some View {
LabeledContent {
if let value {
Text(value.formatted(.currency(code: "EUR")))
} else {
ProgressView()
}
} label: {
Text(type.localizedLabel())
}
.onAppear {
Task {
if value == nil {
value = tournaments.compactMap({ $0.paidSelectedPlayers(type: type) }).reduce(0,+)
}
}
}
}
}
struct CashierDetailDisclosureView: View {
let tournament: Tournament
var body: some View {
DisclosureGroup {
let selectedPlayers = tournament.selectedPlayers()
ForEach(PlayerRegistration.PlayerPaymentType.allCases) { type in
let count = selectedPlayers.filter({ $0.paymentType == type }).count
if count > 0 {
LabeledContent {
if let entryFee = tournament.entryFee {
let sum = Double(count) * entryFee
Text(sum.formatted(.currency(code: "EUR")))
}
} label: {
Text(type.localizedLabel())
Text(count.formatted())
}
}
}
} label: {
Text("Voir le détail")
}
} }
} }
} }

Loading…
Cancel
Save