add locale currency

fix grammar
paca_championship
Raz 1 year ago
parent b6e8144bfd
commit 0c0b492d8f
  1. 4
      PadelClub.xcodeproj/project.pbxproj
  2. 2
      PadelClub/Data/Tournament.swift
  3. 5
      PadelClub/Extensions/Locale+Extensions.swift
  4. 8
      PadelClub/Views/Cashier/CashierDetailView.swift
  5. 59
      PadelClub/Views/Cashier/CashierSettingsView.swift
  6. 8
      PadelClub/Views/Planning/PlanningByCourtView.swift
  7. 4
      PadelClub/Views/Tournament/Screen/Components/TournamentGeneralSettingsView.swift

@ -3246,7 +3246,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.27; MARKETING_VERSION = 1.0.28;
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
@ -3290,7 +3290,7 @@
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0.27; MARKETING_VERSION = 1.0.28;
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";

@ -1592,7 +1592,7 @@ defer {
var entryFeeMessage: String { var entryFeeMessage: String {
if let entryFee { if let entryFee {
let message: String = "Inscription: \(entryFee.formatted(.currency(code: "EUR"))) par joueur." let message: String = "Inscription : \(entryFee.formatted(.currency(code: Locale.defaultCurrency()))) par joueur."
return [message, self._paymentMethodMessage()].compactMap { $0 }.joined(separator: "\n") return [message, self._paymentMethodMessage()].compactMap { $0 }.joined(separator: "\n")
} else { } else {
return "Inscription : gratuite." return "Inscription : gratuite."

@ -20,4 +20,9 @@ extension Locale {
return countries.sorted() return countries.sorted()
} }
static func defaultCurrency() -> String {
// return "EUR"
Locale.current.currency?.identifier ?? "EUR"
}
} }

@ -26,7 +26,7 @@ struct CashierDetailView: View {
Section { Section {
LabeledContent { LabeledContent {
if let earnings { if let earnings {
Text(earnings.formatted(.currency(code: "EUR").precision(.fractionLength(0)))) Text(earnings.formatted(.currency(code: Locale.defaultCurrency()).precision(.fractionLength(0))))
} else { } else {
ProgressView() ProgressView()
} }
@ -95,7 +95,7 @@ struct CashierDetailView: View {
Section { Section {
LabeledContent { LabeledContent {
if let earnings { if let earnings {
Text(earnings.formatted(.currency(code: "EUR").precision(.fractionLength(0)))) Text(earnings.formatted(.currency(code: Locale.defaultCurrency()).precision(.fractionLength(0))))
} else { } else {
ProgressView() ProgressView()
} }
@ -144,7 +144,7 @@ struct CashierDetailView: View {
var body: some View { var body: some View {
LabeledContent { LabeledContent {
if let value { if let value {
Text(value.formatted(.currency(code: "EUR"))) Text(value.formatted(.currency(code: Locale.defaultCurrency())))
} else { } else {
ProgressView() ProgressView()
} }
@ -173,7 +173,7 @@ struct CashierDetailView: View {
LabeledContent { LabeledContent {
if let entryFee = tournament.entryFee { if let entryFee = tournament.entryFee {
let sum = Double(count) * entryFee let sum = Double(count) * entryFee
Text(sum.formatted(.currency(code: "EUR"))) Text(sum.formatted(.currency(code: Locale.defaultCurrency())))
} }
} label: { } label: {
Text(type.localizedLabel()) Text(type.localizedLabel())

@ -24,87 +24,74 @@ struct CashierSettingsView: View {
var body: some View { var body: some View {
List { List {
Section { Section {
LabeledContent { TextField(tournament.isFree() ? "Gratuite" : "Inscription", value: $entryFee, format: .currency(code: Locale.defaultCurrency()))
TextField(tournament.isFree() ? "Gratuite" : "Inscription", value: $entryFee, format: .currency(code: Locale.current.currency?.identifier ?? "EUR"))
.keyboardType(.decimalPad) .keyboardType(.decimalPad)
.multilineTextAlignment(.trailing) .multilineTextAlignment(.trailing)
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)
.focused($focusedField, equals: ._entryFee) .focused($focusedField, equals: ._entryFee)
} label: { } header: {
Text("Inscription") Text("Prix de l'inscription")
}
} footer: { } footer: {
Text("Si vous souhaitez que Padel Club vous aide à suivre les encaissements, indiquer un prix d'inscription. Sinon Padel Club vous aidera à suivre simplement l'arrivée et la présence des joueurs.") Text("Si vous souhaitez que Padel Club vous aide à suivre les encaissements, indiquer un prix d'inscription. Sinon Padel Club vous aidera à suivre simplement l'arrivée et la présence des joueurs.")
} }
let players = tournament.selectedPlayers()
if players.anySatisfy({ $0.hasArrived == false }) {
Section { Section {
RowButtonView("Tout le monde est arrivé", role: .destructive) { RowButtonView("Tout le monde est arrivé", role: .destructive) {
let players = tournament.selectedPlayers() // tournaments.flatMap({ $0.selectedPlayers() })
players.forEach { player in players.forEach { player in
player.hasArrived = true player.hasArrived = true
} }
do { _save(players: players)
try tournament.tournamentStore.playerRegistrations.addOrUpdate(contentOfs: players)
} catch {
Logger.error(error)
}
} }
} footer: { } footer: {
Text("Indique tous les joueurs sont là") Text("Indique tous les joueurs sont là")
} }
}
if players.anySatisfy({ $0.hasArrived == true }) {
Section { Section {
RowButtonView("Personne n'est là", role: .destructive) { RowButtonView("Personne n'est là", role: .destructive) {
let players = tournament.selectedPlayers() // tournaments.flatMap({ $0.selectedPlayers() })
players.forEach { player in players.forEach { player in
player.hasArrived = false player.hasArrived = false
} }
do { _save(players: players)
try tournament.tournamentStore.playerRegistrations.addOrUpdate(contentOfs: players)
} catch {
Logger.error(error)
}
} }
} footer: { } footer: {
Text("Indique qu'aucun joueur n'est arrivé") Text("Indique qu'aucun joueur n'est arrivé")
} }
}
if players.anySatisfy({ $0.hasPaid() == false }) {
Section { Section {
RowButtonView("Tout le monde a réglé", role: .destructive) { RowButtonView("Tout le monde a réglé", role: .destructive) {
let players = tournament.selectedPlayers() // tournaments.flatMap({ $0.selectedPlayers() })
players.forEach { player in players.forEach { player in
if player.hasPaid() == false { if player.hasPaid() == false {
player.paymentType = .gift player.paymentType = .gift
} }
} }
do { _save(players: players)
try tournament.tournamentStore.playerRegistrations.addOrUpdate(contentOfs: players)
} catch {
Logger.error(error)
}
} }
} footer: { } footer: {
Text("Passe tous les joueurs qui n'ont pas réglé en offert") Text("Passe tous les joueurs qui n'ont pas réglé en offert")
} }
}
if players.anySatisfy({ $0.hasPaid() == true }) {
Section { Section {
RowButtonView("Personne n'a réglé", role: .destructive) { RowButtonView("Personne n'a réglé", role: .destructive) {
let store = tournament.tournamentStore
let players = tournament.selectedPlayers()
players.forEach { player in players.forEach { player in
player.paymentType = nil player.paymentType = nil
} }
do { _save(players: players)
try store.playerRegistrations.addOrUpdate(contentOfs: players)
} catch {
Logger.error(error)
}
} }
} footer: { } footer: {
Text("Remet à zéro le type d'encaissement de tous les joueurs") Text("Remet à zéro le type d'encaissement de tous les joueurs")
} }
} }
}
.navigationBarBackButtonHidden(focusedField != nil) .navigationBarBackButtonHidden(focusedField != nil)
.toolbarBackground(.visible, for: .navigationBar) .toolbarBackground(.visible, for: .navigationBar)
.toolbar { .toolbar {
@ -119,7 +106,7 @@ struct CashierSettingsView: View {
HStack { HStack {
if tournament.isFree() { if tournament.isFree() {
ForEach(priceTags, id: \.self) { priceTag in ForEach(priceTags, id: \.self) { priceTag in
Button(priceTag.formatted(.currency(code: "EUR"))) { Button(priceTag.formatted(.currency(code: Locale.defaultCurrency()))) {
entryFee = priceTag entryFee = priceTag
tournament.entryFee = priceTag tournament.entryFee = priceTag
focusedField = nil focusedField = nil
@ -150,6 +137,14 @@ struct CashierSettingsView: View {
} }
} }
private func _save(players: [PlayerRegistration]) {
do {
try tournament.tournamentStore.playerRegistrations.addOrUpdate(contentOfs: players)
} catch {
Logger.error(error)
}
}
private func _save() { private func _save() {
do { do {
try dataStore.tournaments.addOrUpdate(instance: tournament) try dataStore.tournaments.addOrUpdate(instance: tournament)

@ -132,17 +132,17 @@ struct PlanningByCourtView: View {
} }
} else if noStartDate == false { } else if noStartDate == false {
ContentUnavailableView { ContentUnavailableView {
Label("Aucun match plannifié", systemImage: "clock.badge.questionmark") Label("Aucun match planifié", systemImage: "clock.badge.questionmark")
} description: { } description: {
Text("Aucun match n'a été plannifié sur ce terrain et au jour sélectionné") Text("Aucun match n'a été planifié sur ce terrain et au jour sélectionné")
} actions: { } actions: {
} }
} }
} else if noStartDate == false { } else if noStartDate == false {
ContentUnavailableView { ContentUnavailableView {
Label("Aucun match plannifié", systemImage: "clock.badge.questionmark") Label("Aucun match planifié", systemImage: "clock.badge.questionmark")
} description: { } description: {
Text("Aucun match n'a été plannifié sur ce terrain et au jour sélectionné") Text("Aucun match n'a été planifié sur ce terrain et au jour sélectionné")
} actions: { } actions: {
} }
} }

@ -45,7 +45,7 @@ struct TournamentGeneralSettingsView: View {
TournamentDatePickerView() TournamentDatePickerView()
TournamentDurationManagerView() TournamentDurationManagerView()
LabeledContent { LabeledContent {
TextField(tournament.isFree() ? "Gratuite" : "Inscription", value: $entryFee, format: .currency(code: Locale.current.currency?.identifier ?? "EUR")) TextField(tournament.isFree() ? "Gratuite" : "Inscription", value: $entryFee, format: .currency(code: Locale.defaultCurrency()))
.keyboardType(.decimalPad) .keyboardType(.decimalPad)
.multilineTextAlignment(.trailing) .multilineTextAlignment(.trailing)
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)
@ -125,7 +125,7 @@ struct TournamentGeneralSettingsView: View {
if focusedField == ._entryFee { if focusedField == ._entryFee {
if tournament.isFree() { if tournament.isFree() {
ForEach(priceTags, id: \.self) { priceTag in ForEach(priceTags, id: \.self) { priceTag in
Button(priceTag.formatted(.currency(code: "EUR"))) { Button(priceTag.formatted(.currency(code: Locale.defaultCurrency()))) {
entryFee = priceTag entryFee = priceTag
tournament.entryFee = priceTag tournament.entryFee = priceTag
focusedField = nil focusedField = nil

Loading…
Cancel
Save