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 {
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: {

@ -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)
})
}

@ -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 {

@ -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))
}
}
}

Loading…
Cancel
Save