add remaining amount in event / tournament

sync3
Raz 6 months ago
parent d910ca1646
commit a2eed6d4eb
  1. 8
      PadelClub/Data/Tournament.swift
  2. 34
      PadelClub/Views/Cashier/CashierDetailView.swift

@ -1425,6 +1425,14 @@ defer {
return 0.0 return 0.0
} }
} }
func remainingAmount() -> Double {
if let entryFee {
return Double(selectedPlayers().filter { $0.hasPaid() == false }.count) * entryFee
} else {
return 0.0
}
}
func paidCompletion() -> Double { func paidCompletion() -> Double {
let selectedPlayers = selectedPlayers() let selectedPlayers = selectedPlayers()

@ -10,6 +10,7 @@ import SwiftUI
struct CashierDetailView: View { struct CashierDetailView: View {
var tournaments : [Tournament] var tournaments : [Tournament]
@State private var earnings: Double? = nil @State private var earnings: Double? = nil
@State private var remainingAmount: Double? = nil
@State private var paidCompletion: Double? = nil @State private var paidCompletion: Double? = nil
init(tournaments: [Tournament]) { init(tournaments: [Tournament]) {
@ -24,6 +25,16 @@ struct CashierDetailView: View {
List { List {
if tournaments.count > 1 { if tournaments.count > 1 {
Section { Section {
LabeledContent {
if let remainingAmount {
Text(remainingAmount.formatted(.currency(code: Locale.defaultCurrency()).precision(.fractionLength(0))))
} else {
ProgressView()
}
} label: {
Text("Reste à encaisser")
}
LabeledContent { LabeledContent {
if let earnings { if let earnings {
Text(earnings.formatted(.currency(code: Locale.defaultCurrency()).precision(.fractionLength(0)))) Text(earnings.formatted(.currency(code: Locale.defaultCurrency()).precision(.fractionLength(0))))
@ -57,10 +68,18 @@ struct CashierDetailView: View {
if paidCompletion == nil { if paidCompletion == nil {
_getPaidCompletion() _getPaidCompletion()
} }
if remainingAmount == nil {
_getRemainingAmount()
}
} }
} }
} }
private func _getRemainingAmount() {
remainingAmount = tournaments.map { $0.remainingAmount() }.reduce(0,+)
}
private func _getEarnings() { private func _getEarnings() {
earnings = tournaments.map { $0.earnings() }.reduce(0,+) earnings = tournaments.map { $0.earnings() }.reduce(0,+)
} }
@ -88,11 +107,22 @@ struct CashierDetailView: View {
let tournament: Tournament let tournament: Tournament
let showTournamentTitle: Bool let showTournamentTitle: Bool
@State private var earnings: Double? = nil @State private var earnings: Double? = nil
@State private var remainingAmount: Double? = nil
@State private var paidCompletion: Double? = nil @State private var paidCompletion: Double? = nil
@State private var presence: Double? = nil @State private var presence: Double? = nil
var body: some View { var body: some View {
Section { Section {
LabeledContent {
if let remainingAmount {
Text(remainingAmount.formatted(.currency(code: Locale.defaultCurrency()).precision(.fractionLength(0))))
} else {
ProgressView()
}
} label: {
Text("Reste à encaisser")
}
LabeledContent { LabeledContent {
if let earnings { if let earnings {
Text(earnings.formatted(.currency(code: Locale.defaultCurrency()).precision(.fractionLength(0)))) Text(earnings.formatted(.currency(code: Locale.defaultCurrency()).precision(.fractionLength(0))))
@ -130,6 +160,10 @@ struct CashierDetailView: View {
if presence == nil { if presence == nil {
presence = tournament.presenceStatus() presence = tournament.presenceStatus()
} }
if remainingAmount == nil {
remainingAmount = tournament.remainingAmount()
}
} }
} }
} }

Loading…
Cancel
Save