fix stuff cashier

multistore
Razmig Sarkissian 1 year ago
parent f3f2ebd032
commit d720c215f1
  1. 2
      PadelClub/Views/Cashier/CashierDetailView.swift
  2. 9
      PadelClub/Views/Cashier/CashierView.swift
  3. 39
      PadelClub/Views/Planning/PlanningSettingsView.swift
  4. 12
      PadelClub/Views/Tournament/Screen/TournamentCashierView.swift

@ -43,6 +43,7 @@ struct CashierDetailView: View {
DisclosureGroup { DisclosureGroup {
ForEach(PlayerRegistration.PlayerPaymentType.allCases) { type in ForEach(PlayerRegistration.PlayerPaymentType.allCases) { type in
let count = tournament.selectedPlayers().filter({ $0.paymentType == type }).count let count = tournament.selectedPlayers().filter({ $0.paymentType == type }).count
if count > 0 {
LabeledContent { LabeledContent {
if let entryFee = tournament.entryFee { if let entryFee = tournament.entryFee {
let sum = Double(count) * entryFee let sum = Double(count) * entryFee
@ -53,6 +54,7 @@ struct CashierDetailView: View {
Text(count.formatted()) Text(count.formatted())
} }
} }
}
} label: { } label: {
Text("Voir le détail") Text("Voir le détail")
} }

@ -21,6 +21,9 @@ struct CashierView: View {
init(tournament: Tournament, teams: [TeamRegistration]) { init(tournament: Tournament, teams: [TeamRegistration]) {
self.tournaments = [tournament] self.tournaments = [tournament]
self.teams = teams self.teams = teams
if tournament.hasEnded(), tournament.paidCompletion() < 100.0 {
_filterOption = .init(wrappedValue: .didNotPay)
}
if teams.filter({ $0.callDate != nil }).isEmpty { if teams.filter({ $0.callDate != nil }).isEmpty {
_sortOption = .init(wrappedValue: .teamRank) _sortOption = .init(wrappedValue: .teamRank)
} else { } else {
@ -29,8 +32,8 @@ struct CashierView: View {
} }
private func _sharedData() -> String { private func _sharedData() -> String {
let players = teams let players = teams.filter({ _shouldDisplayTeam($0) })
.flatMap({ $0.players() }) .flatMap({ $0.players().filter({ _shouldDisplayPlayer($0) }) })
.map { .map {
[$0.pasteData()] [$0.pasteData()]
.compacted() .compacted()
@ -163,7 +166,7 @@ struct CashierView: View {
} }
private func _shouldDisplayTeam(_ team: TeamRegistration) -> Bool { private func _shouldDisplayTeam(_ team: TeamRegistration) -> Bool {
team.players().allSatisfy({ team.players().anySatisfy({
_shouldDisplayPlayer($0) _shouldDisplayPlayer($0)
}) })
} }

@ -94,29 +94,22 @@ struct PlanningSettingsView: View {
Text("Voir les options avancées") Text("Voir les options avancées")
} }
Section { let allMatches = tournament.allMatches()
RowButtonView("Horaire intelligent", role: .destructive) { let allGroupStages = tournament.groupStages()
schedulingDone = false let allRounds = tournament.allRounds()
await _setupSchedule() let matchesWithDate = allMatches.filter({ $0.startDate != nil })
_save() let groupStagesWithDate = allGroupStages.filter({ $0.startDate != nil })
schedulingDone = true let roundsWithDate = allRounds.filter({ $0.startDate != nil })
} if matchesWithDate.isEmpty == false || groupStagesWithDate.isEmpty == false || roundsWithDate.isEmpty == false {
} footer: {
Text("Padel Club programmera tous les matchs de votre tournoi en fonction de différents paramètres, ") + Text("tout en tenant compte des horaires que vous avez fixé.").underline()
}
Section { Section {
RowButtonView("Supprimer tous les horaires", role: .destructive) { RowButtonView("Supprimer tous les horaires", role: .destructive) {
do { do {
let allMatches = tournament.allMatches()
allMatches.forEach({ $0.startDate = nil }) allMatches.forEach({ $0.startDate = nil })
try dataStore.matches.addOrUpdate(contentOfs: allMatches) try dataStore.matches.addOrUpdate(contentOfs: allMatches)
let allGroupStages = tournament.groupStages()
allGroupStages.forEach({ $0.startDate = nil }) allGroupStages.forEach({ $0.startDate = nil })
try dataStore.groupStages.addOrUpdate(contentOfs: allGroupStages) try dataStore.groupStages.addOrUpdate(contentOfs: allGroupStages)
let allRounds = tournament.allRounds()
allRounds.forEach({ $0.startDate = nil }) allRounds.forEach({ $0.startDate = nil })
try dataStore.rounds.addOrUpdate(contentOfs: allRounds) try dataStore.rounds.addOrUpdate(contentOfs: allRounds)
} catch { } catch {
@ -125,6 +118,24 @@ struct PlanningSettingsView: View {
} }
} }
} }
Section {
if groupStagesWithDate.isEmpty == false {
Text("Des dates de démarrages ont été indiqué pour les poules et seront prises en compte.")
}
if roundsWithDate.isEmpty == false {
Text("Des dates de démarrages ont été indiqué pour les manches et seront prises en compte.")
}
RowButtonView("Horaire intelligent", role: .destructive, confirmationMessage: "L") {
schedulingDone = false
await _setupSchedule()
_save()
schedulingDone = true
}
} footer: {
Text("Padel Club programmera tous les matchs de votre tournoi en fonction de différents paramètres, ") + Text("tout en tenant compte des horaires que vous avez fixé.").underline()
}
}
.headerProminence(.increased) .headerProminence(.increased)
.onAppear { .onAppear {
do { do {

@ -78,9 +78,10 @@ struct TournamentCashierView: View {
let tournamentHasEnded = tournament.hasEnded() let tournamentHasEnded = tournament.hasEnded()
if tournamentHasEnded { if tournamentHasEnded {
allDestinations.append(.summary) allDestinations.append(.summary)
allDestinations.append(.all(tournament))
} }
allDestinations.append(.all(tournament))
let destinations : [CashierDestination] = tournament.groupStages().map { CashierDestination.groupStage($0) } let destinations : [CashierDestination] = tournament.groupStages().map { CashierDestination.groupStage($0) }
allDestinations.append(contentsOf: destinations) allDestinations.append(contentsOf: destinations)
tournament.rounds().forEach { round in tournament.rounds().forEach { round in
@ -90,7 +91,6 @@ struct TournamentCashierView: View {
} }
if tournamentHasEnded == false { if tournamentHasEnded == false {
allDestinations.append(.all(tournament))
allDestinations.append(.summary) allDestinations.append(.summary)
} }
@ -99,6 +99,13 @@ struct TournamentCashierView: View {
init(tournament: Tournament) { init(tournament: Tournament) {
self.tournament = tournament self.tournament = tournament
if tournament.hasEnded() {
if tournament.paidCompletion() == 100.0 {
_selectedDestination = .init(wrappedValue: .summary)
} else {
_selectedDestination = .init(wrappedValue: .all(tournament))
}
} else {
let gs = tournament.getActiveGroupStage() let gs = tournament.getActiveGroupStage()
if let gs { if let gs {
_selectedDestination = State(wrappedValue: .groupStage(gs)) _selectedDestination = State(wrappedValue: .groupStage(gs))
@ -106,6 +113,7 @@ struct TournamentCashierView: View {
_selectedDestination = State(wrappedValue: .bracket(rs)) _selectedDestination = State(wrappedValue: .bracket(rs))
} }
} }
}
var body: some View { var body: some View {
VStack(spacing: 0) { VStack(spacing: 0) {

Loading…
Cancel
Save