diff --git a/PadelClubData/Data/Event.swift b/PadelClubData/Data/Event.swift index 8563e3a..302cb63 100644 --- a/PadelClubData/Data/Event.swift +++ b/PadelClubData/Data/Event.swift @@ -92,6 +92,10 @@ final public class Event: BaseEvent { tournaments.filter({ $0.isFree() == false && $0.isCanceled == false && $0.isDeleted == false }) } + public func confirmedTournaments() -> [Tournament] { + tournaments.filter({ $0.isCanceled == false && $0.isDeleted == false }) + } + public func shareURL() -> URL? { return URL(string: URLs.main.url.appending(path: "event/\(id)").absoluteString.removingPercentEncoding!) } diff --git a/PadelClubData/Data/GroupStage.swift b/PadelClubData/Data/GroupStage.swift index 4c74d03..3f2cae4 100644 --- a/PadelClubData/Data/GroupStage.swift +++ b/PadelClubData/Data/GroupStage.swift @@ -606,6 +606,10 @@ final public class GroupStage: BaseGroupStage, SideStorable { guard hasEnded() else { return nil } return teams(true).firstIndex(of: team) } + + public func computedStartDate() -> Date? { + return _matches().sorted(by: \.computedStartDateForSorting).first?.startDate + } public override func deleteDependencies(store: Store, actionOption: ActionOption) { store.deleteDependencies(type: Match.self, actionOption: actionOption) { $0.groupStage == self.id } diff --git a/PadelClubData/Data/Match.swift b/PadelClubData/Data/Match.swift index dde0231..3d7b68c 100644 --- a/PadelClubData/Data/Match.swift +++ b/PadelClubData/Data/Match.swift @@ -525,6 +525,16 @@ defer { updateFollowingMatchTeamScore() } + public func teamPosition(for teamRegistration: TeamRegistration) -> TeamPosition? { + if self.team(.one)?.id == teamRegistration.id { + return .one + } else if self.team(.two)?.id == teamRegistration.id { + return .two + } else { + return nil + } + } + public func setWalkOut(_ teamPosition: TeamPosition) { let teamScoreWalkout = teamScore(teamPosition) ?? TeamScore(match: id, team: team(teamPosition)) teamScoreWalkout.walkOut = 0 diff --git a/PadelClubData/Data/MatchScheduler.swift b/PadelClubData/Data/MatchScheduler.swift index 2c69b95..33b11e1 100644 --- a/PadelClubData/Data/MatchScheduler.swift +++ b/PadelClubData/Data/MatchScheduler.swift @@ -131,6 +131,9 @@ final public class MatchScheduler: BaseMatchScheduler, SideStorable { } catch { Logger.error(error) } + + groupStages.forEach({ $0.startDate = $0.computedStartDate() }) + self.tournamentStore?.groupStages.addOrUpdate(contentOfs: groupStages) return lastDate } diff --git a/PadelClubData/Data/PlayerRegistration.swift b/PadelClubData/Data/PlayerRegistration.swift index 773934b..afc6c4d 100644 --- a/PadelClubData/Data/PlayerRegistration.swift +++ b/PadelClubData/Data/PlayerRegistration.swift @@ -230,7 +230,18 @@ final public class PlayerRegistration: BasePlayerRegistration, SideStorable { return 0.0 } } - + + public func totalIncome(_ tournament: Tournament) -> Double { + if let entryFee = tournament.entryFee { + if clubMember, let clubMemberFeeDeduction = tournament.clubMemberFeeDeduction { + return entryFee - clubMemberFeeDeduction + } else { + return entryFee + } + } else { + return 0.0 + } + } public enum PlayerDataSource: Int, Codable { case frenchFederation = 0 diff --git a/PadelClubData/Data/Tournament.swift b/PadelClubData/Data/Tournament.swift index 3bd3899..2212862 100644 --- a/PadelClubData/Data/Tournament.swift +++ b/PadelClubData/Data/Tournament.swift @@ -1251,6 +1251,15 @@ defer { public func remainingAmount() -> Double { return selectedPlayers().compactMap { $0.remainingAmount(self) }.reduce(0.0, +) } + + public func totalIncome() -> Double { + if let entryFee { + return Double(teamCount) * entryFee * 2.0 + } else { + return 0.0 + } + } + public func paidCompletion() -> Double { let selectedPlayers = selectedPlayers() diff --git a/PadelClubData/ViewModel/PadelRule.swift b/PadelClubData/ViewModel/PadelRule.swift index 152d23d..8cc6a51 100644 --- a/PadelClubData/ViewModel/PadelRule.swift +++ b/PadelClubData/ViewModel/PadelRule.swift @@ -1273,7 +1273,7 @@ public enum MatchFormat: Int, Hashable, Codable, CaseIterable, Identifiable { self.init(rawValue: value) } - func defaultWalkOutScore(_ asWalkOutTeam: Bool) -> [Int] { + public func defaultWalkOutScore(_ asWalkOutTeam: Bool) -> [Int] { Array(repeating: asWalkOutTeam ? 0 : setFormat.scoreToWin, count: setsToWin) } diff --git a/PadelClubData/ViewModel/Screen.swift b/PadelClubData/ViewModel/Screen.swift index 251ac6b..bb53ac7 100644 --- a/PadelClubData/ViewModel/Screen.swift +++ b/PadelClubData/ViewModel/Screen.swift @@ -23,4 +23,5 @@ public enum Screen: String, Codable { case share case restingTime case stateSettings + case statistics }