fix stuff cashier

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

@ -43,14 +43,16 @@ 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
LabeledContent { if count > 0 {
if let entryFee = tournament.entryFee { LabeledContent {
let sum = Double(count) * entryFee if let entryFee = tournament.entryFee {
Text(sum.formatted(.currency(code: "EUR"))) 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: { } label: {

@ -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,8 +94,39 @@ struct PlanningSettingsView: View {
Text("Voir les options avancées") 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 { 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 schedulingDone = false
await _setupSchedule() await _setupSchedule()
_save() _save()
@ -104,26 +135,6 @@ struct PlanningSettingsView: View {
} footer: { } 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() 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) .headerProminence(.increased)
.onAppear { .onAppear {

@ -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,11 +99,19 @@ struct TournamentCashierView: View {
init(tournament: Tournament) { init(tournament: Tournament) {
self.tournament = tournament self.tournament = tournament
let gs = tournament.getActiveGroupStage() if tournament.hasEnded() {
if let gs { if tournament.paidCompletion() == 100.0 {
_selectedDestination = State(wrappedValue: .groupStage(gs)) _selectedDestination = .init(wrappedValue: .summary)
} else if let rs = tournament.getActiveRound(withSeeds: true) { } else {
_selectedDestination = State(wrappedValue: .bracket(rs)) _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))
}
} }
} }

Loading…
Cancel
Save