From d720c215f1ea04d3f9c0e05dcb899b32fe79b94c Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Wed, 29 May 2024 10:07:02 +0200 Subject: [PATCH] fix stuff cashier --- .../Views/Cashier/CashierDetailView.swift | 16 +++--- PadelClub/Views/Cashier/CashierView.swift | 9 ++-- .../Views/Planning/PlanningSettingsView.swift | 53 +++++++++++-------- .../Screen/TournamentCashierView.swift | 24 ++++++--- 4 files changed, 63 insertions(+), 39 deletions(-) diff --git a/PadelClub/Views/Cashier/CashierDetailView.swift b/PadelClub/Views/Cashier/CashierDetailView.swift index 4e581ad..c262b32 100644 --- a/PadelClub/Views/Cashier/CashierDetailView.swift +++ b/PadelClub/Views/Cashier/CashierDetailView.swift @@ -43,14 +43,16 @@ struct CashierDetailView: View { DisclosureGroup { ForEach(PlayerRegistration.PlayerPaymentType.allCases) { type in let count = tournament.selectedPlayers().filter({ $0.paymentType == type }).count - LabeledContent { - if let entryFee = tournament.entryFee { - let sum = Double(count) * entryFee - Text(sum.formatted(.currency(code: "EUR"))) + 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(type.localizedLabel()) - Text(count.formatted()) } } } label: { diff --git a/PadelClub/Views/Cashier/CashierView.swift b/PadelClub/Views/Cashier/CashierView.swift index 5ca8df8..bed78fe 100644 --- a/PadelClub/Views/Cashier/CashierView.swift +++ b/PadelClub/Views/Cashier/CashierView.swift @@ -21,6 +21,9 @@ struct CashierView: View { init(tournament: Tournament, teams: [TeamRegistration]) { self.tournaments = [tournament] self.teams = teams + if tournament.hasEnded(), tournament.paidCompletion() < 100.0 { + _filterOption = .init(wrappedValue: .didNotPay) + } if teams.filter({ $0.callDate != nil }).isEmpty { _sortOption = .init(wrappedValue: .teamRank) } else { @@ -29,8 +32,8 @@ struct CashierView: View { } private func _sharedData() -> String { - let players = teams - .flatMap({ $0.players() }) + let players = teams.filter({ _shouldDisplayTeam($0) }) + .flatMap({ $0.players().filter({ _shouldDisplayPlayer($0) }) }) .map { [$0.pasteData()] .compacted() @@ -163,7 +166,7 @@ struct CashierView: View { } private func _shouldDisplayTeam(_ team: TeamRegistration) -> Bool { - team.players().allSatisfy({ + team.players().anySatisfy({ _shouldDisplayPlayer($0) }) } diff --git a/PadelClub/Views/Planning/PlanningSettingsView.swift b/PadelClub/Views/Planning/PlanningSettingsView.swift index 66b71be..8d61aad 100644 --- a/PadelClub/Views/Planning/PlanningSettingsView.swift +++ b/PadelClub/Views/Planning/PlanningSettingsView.swift @@ -94,8 +94,39 @@ struct PlanningSettingsView: View { Text("Voir les options avancées") } + let allMatches = tournament.allMatches() + let allGroupStages = tournament.groupStages() + let allRounds = tournament.allRounds() + let matchesWithDate = allMatches.filter({ $0.startDate != nil }) + let groupStagesWithDate = allGroupStages.filter({ $0.startDate != nil }) + let roundsWithDate = allRounds.filter({ $0.startDate != nil }) + if matchesWithDate.isEmpty == false || groupStagesWithDate.isEmpty == false || roundsWithDate.isEmpty == false { + Section { + RowButtonView("Supprimer tous les horaires", role: .destructive) { + do { + allMatches.forEach({ $0.startDate = nil }) + try dataStore.matches.addOrUpdate(contentOfs: allMatches) + + allGroupStages.forEach({ $0.startDate = nil }) + try dataStore.groupStages.addOrUpdate(contentOfs: allGroupStages) + + allRounds.forEach({ $0.startDate = nil }) + try dataStore.rounds.addOrUpdate(contentOfs: allRounds) + } catch { + Logger.error(error) + } + } + } + } + Section { - RowButtonView("Horaire intelligent", role: .destructive) { + 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() @@ -104,26 +135,6 @@ struct PlanningSettingsView: View { } 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 { - RowButtonView("Supprimer tous les horaires", role: .destructive) { - do { - let allMatches = tournament.allMatches() - allMatches.forEach({ $0.startDate = nil }) - try dataStore.matches.addOrUpdate(contentOfs: allMatches) - - let allGroupStages = tournament.groupStages() - allGroupStages.forEach({ $0.startDate = nil }) - try dataStore.groupStages.addOrUpdate(contentOfs: allGroupStages) - - let allRounds = tournament.allRounds() - allRounds.forEach({ $0.startDate = nil }) - try dataStore.rounds.addOrUpdate(contentOfs: allRounds) - } catch { - Logger.error(error) - } - } - } } .headerProminence(.increased) .onAppear { diff --git a/PadelClub/Views/Tournament/Screen/TournamentCashierView.swift b/PadelClub/Views/Tournament/Screen/TournamentCashierView.swift index ff51c2d..6fea6a1 100644 --- a/PadelClub/Views/Tournament/Screen/TournamentCashierView.swift +++ b/PadelClub/Views/Tournament/Screen/TournamentCashierView.swift @@ -78,9 +78,10 @@ struct TournamentCashierView: View { let tournamentHasEnded = tournament.hasEnded() if tournamentHasEnded { allDestinations.append(.summary) - allDestinations.append(.all(tournament)) } - + + allDestinations.append(.all(tournament)) + let destinations : [CashierDestination] = tournament.groupStages().map { CashierDestination.groupStage($0) } allDestinations.append(contentsOf: destinations) tournament.rounds().forEach { round in @@ -90,7 +91,6 @@ struct TournamentCashierView: View { } if tournamentHasEnded == false { - allDestinations.append(.all(tournament)) allDestinations.append(.summary) } @@ -99,11 +99,19 @@ struct TournamentCashierView: View { init(tournament: Tournament) { self.tournament = tournament - let gs = tournament.getActiveGroupStage() - if let gs { - _selectedDestination = State(wrappedValue: .groupStage(gs)) - } else if let rs = tournament.getActiveRound(withSeeds: true) { - _selectedDestination = State(wrappedValue: .bracket(rs)) + if tournament.hasEnded() { + if tournament.paidCompletion() == 100.0 { + _selectedDestination = .init(wrappedValue: .summary) + } else { + _selectedDestination = .init(wrappedValue: .all(tournament)) + } + } else { + let gs = tournament.getActiveGroupStage() + if let gs { + _selectedDestination = State(wrappedValue: .groupStage(gs)) + } else if let rs = tournament.getActiveRound(withSeeds: true) { + _selectedDestination = State(wrappedValue: .bracket(rs)) + } } }