|  | @@ -1,247 +0,0 @@
 | 
											
												
													
														|  | -import { actions, reducer, state, saga } from './state'
 |  | 
 | 
											
												
													
														|  | -import components from './components'
 |  | 
 | 
											
												
													
														|  | -import { date2s, time2s } from '../helpers'
 |  | 
 | 
											
												
													
														|  | -import Match from '../classes/match'
 |  | 
 | 
											
												
													
														|  | -import Excel from '../excel'
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -const filters = {
 |  | 
 | 
											
												
													
														|  | -  all: players => players
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -const selectors = {}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -export default { actions, components, filters, selectors, reducer, state, saga }
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -const PLACES = {
 |  | 
 | 
											
												
													
														|  | -  'LE': 'TC Lerchenberg',
 |  | 
 | 
											
												
													
														|  | -  'WA': 'TC Waidberg',
 |  | 
 | 
											
												
													
														|  | -  'VA': 'TC Valsana',
 |  | 
 | 
											
												
													
														|  | -  'SE': 'TC Seebach',
 |  | 
 | 
											
												
													
														|  | -  'BU': 'TC Bührle',
 |  | 
 | 
											
												
													
														|  | -  'HO': 'TC Höngg',
 |  | 
 | 
											
												
													
														|  | -  'TS': 'Tennis-Sport Club',
 |  | 
 | 
											
												
													
														|  | -  'HA': 'Städtische Plätze Hardhof',
 |  | 
 | 
											
												
													
														|  | -  'AU': 'Auswärtig'
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -const FILTER_OFF = 'Alle'
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -function calculateMatchFilters () {
 |  | 
 | 
											
												
													
														|  | -  const dates = {}
 |  | 
 | 
											
												
													
														|  | -  const places = []
 |  | 
 | 
											
												
													
														|  | -  const categories = []
 |  | 
 | 
											
												
													
														|  | -  this.state.match.matches.forEach((item) => {
 |  | 
 | 
											
												
													
														|  | -    const dateString = date2s(item.Datum)
 |  | 
 | 
											
												
													
														|  | -    if (!!item.Datum & !dates.hasOwnProperty(dateString)) {
 |  | 
 | 
											
												
													
														|  | -      dates[dateString] = item.Datum
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    if (!!item.Ort & !places.includes(item.Ort)) {
 |  | 
 | 
											
												
													
														|  | -      places.push(item.Ort)
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -    if (!!item.Konkurrenz & !categories.includes(item.Konkurrenz)) {
 |  | 
 | 
											
												
													
														|  | -      categories.push(item.Konkurrenz)
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -  })
 |  | 
 | 
											
												
													
														|  | -  const match = { ...this.state.match, dates, places, categories }
 |  | 
 | 
											
												
													
														|  | -  this.setState({ match })
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -function generateCalendar (worksheet) {
 |  | 
 | 
											
												
													
														|  | -  console.log('About to read the calendar.')
 |  | 
 | 
											
												
													
														|  | -  const worksheets = { ...this.state.worksheets }
 |  | 
 | 
											
												
													
														|  | -  worksheets['Calendar'] = worksheet
 |  | 
 | 
											
												
													
														|  | -  this.setState({ worksheets })
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -  if (worksheet[2].length < 8 | worksheet[2].length > 9) {
 |  | 
 | 
											
												
													
														|  | -    throw Error('Wrong file structure.')
 |  | 
 | 
											
												
													
														|  | -  }
 |  | 
 | 
											
												
													
														|  | -  const matches = worksheet.slice(2, worksheet.length).map((matchData) => new Match.Match(matchData))
 |  | 
 | 
											
												
													
														|  | -  const match = { ...this.state.match }
 |  | 
 | 
											
												
													
														|  | -  match.matches = matches
 |  | 
 | 
											
												
													
														|  | -  this.setState({ match })
 |  | 
 | 
											
												
													
														|  | -  this.calculateMatchFilters()
 |  | 
 | 
											
												
													
														|  | -  this.calculatePayDate()
 |  | 
 | 
											
												
													
														|  | -  this.filterMatches()
 |  | 
 | 
											
												
													
														|  | -  console.log('State after generating calendar:', this.state)
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -function filterMatches () {
 |  | 
 | 
											
												
													
														|  | -  const filters = {
 |  | 
 | 
											
												
													
														|  | -    date: this.matchDate.value !== FILTER_OFF ? this.matchDate.value : null,
 |  | 
 | 
											
												
													
														|  | -    place: this.matchPlace.value !== FILTER_OFF ? this.matchPlace.value : null,
 |  | 
 | 
											
												
													
														|  | -    category: this.matchCategory.value !== FILTER_OFF ? this.matchCategory.value : null
 |  | 
 | 
											
												
													
														|  | -  }
 |  | 
 | 
											
												
													
														|  | -  console.log('New filter settings:', filters)
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -  const match = { ...this.state.match }
 |  | 
 | 
											
												
													
														|  | -  match.filtered = match.matches.filter((match) => {
 |  | 
 | 
											
												
													
														|  | -    const matchDate = new Date(match.Datum)
 |  | 
 | 
											
												
													
														|  | -    matchDate.setHours(0, 0, 0, 0)
 |  | 
 | 
											
												
													
														|  | -    const filtDate = new Date(filters.date)
 |  | 
 | 
											
												
													
														|  | -    filtDate.setHours(0, 0, 0, 0)
 |  | 
 | 
											
												
													
														|  | -    return (!filters.date | matchDate.getTime() === filtDate.getTime()) &
 |  | 
 | 
											
												
													
														|  | -      (!filters.place | filters.place === match.Ort) &
 |  | 
 | 
											
												
													
														|  | -      (!filters.category | filters.category === match.Konkurrenz)
 |  | 
 | 
											
												
													
														|  | -  })
 |  | 
 | 
											
												
													
														|  | -  this.setState({ match })
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -  const player = { ...this.state.player, filters }
 |  | 
 | 
											
												
													
														|  | -  player.filtered = player.players
 |  | 
 | 
											
												
													
														|  | -  this.setState({ player })
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -function generatePhoneList (event) {
 |  | 
 | 
											
												
													
														|  | -  event.preventDefault()
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -  const phoneMail = new Excel.Workbook()
 |  | 
 | 
											
												
													
														|  | -  phoneMail.SheetNames = []
 |  | 
 | 
											
												
													
														|  | -  phoneMail.Sheets = {}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -  const dataList = [
 |  | 
 | 
											
												
													
														|  | -      ['Vorname', 'Nachname', 'Anrede', 'Geschlecht', 'Handy', 'E-Mail']
 |  | 
 | 
											
												
													
														|  | -  ]
 |  | 
 | 
											
												
													
														|  | -  const phonePot = []
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -  const players = this.state.player.filtered
 |  | 
 | 
											
												
													
														|  | -  players.forEach(player => {
 |  | 
 | 
											
												
													
														|  | -    if (!player.phone.match(/^FEHLER/) && !phonePot.includes(player.phone)) {
 |  | 
 | 
											
												
													
														|  | -      phonePot.push(player.phone)
 |  | 
 | 
											
												
													
														|  | -      dataList.push([
 |  | 
 | 
											
												
													
														|  | -        player.Vorname,
 |  | 
 | 
											
												
													
														|  | -        player.Name,
 |  | 
 | 
											
												
													
														|  | -        2,
 |  | 
 | 
											
												
													
														|  | -        player.geschlecht === 'w' ? 2 : 1,
 |  | 
 | 
											
												
													
														|  | -        player.phone
 |  | 
 | 
											
												
													
														|  | -      ])
 |  | 
 | 
											
												
													
														|  | -    }
 |  | 
 | 
											
												
													
														|  | -  })
 |  | 
 | 
											
												
													
														|  | -  phoneMail.Sheets['Sheet1'] = Excel.SheetFromArray(dataList)
 |  | 
 | 
											
												
													
														|  | -  phoneMail.SheetNames.push('Sheet1')
 |  | 
 | 
											
												
													
														|  | -  Excel.saveAs(phoneMail, 'Telefon.xlsx')
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -function calculatePayDate () {
 |  | 
 | 
											
												
													
														|  | -  if ((this.state.player.players.length === 0) | (this.state.match.matches.length === 0)) {
 |  | 
 | 
											
												
													
														|  | -    return
 |  | 
 | 
											
												
													
														|  | -  }
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -  this.state.match.matches.forEach((match) => {
 |  | 
 | 
											
												
													
														|  | -    [match.Spieler1, match.Spieler2].forEach((matchPlayer) => {
 |  | 
 | 
											
												
													
														|  | -      if (matchPlayer) {
 |  | 
 | 
											
												
													
														|  | -        let foundPlayer = this.state.player.players.find((player) =>
 |  | 
 | 
											
												
													
														|  | -            (player.name === matchPlayer) & (player.Konkurrenz === match.Konkurrenz)
 |  | 
 | 
											
												
													
														|  | -          )
 |  | 
 | 
											
												
													
														|  | -        if (!foundPlayer) {
 |  | 
 | 
											
												
													
														|  | -          console.log('Debug payerlist:', foundPlayer, match)
 |  | 
 | 
											
												
													
														|  | -          throw Error('Match player not found in player list. This is an error!')
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -        if (!foundPlayer.BezahltAm) {
 |  | 
 | 
											
												
													
														|  | -          foundPlayer.BezahltAm = match.Datum
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -      }
 |  | 
 | 
											
												
													
														|  | -    })
 |  | 
 | 
											
												
													
														|  | -  })
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -function generatePayTable (event) {
 |  | 
 | 
											
												
													
														|  | -  event.preventDefault()
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -  const paylist = new Excel.Workbook()
 |  | 
 | 
											
												
													
														|  | -  paylist.SheetNames = []
 |  | 
 | 
											
												
													
														|  | -  paylist.Sheets = {}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -  const worksheets = {}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -  let placeArray = this.state.match.places
 |  | 
 | 
											
												
													
														|  | -    /* if (placeArray.length > 1) {
 |  | 
 | 
											
												
													
														|  | -      placeArray = placeArray.concat([FILTER_OFF])
 |  | 
 | 
											
												
													
														|  | -    } */
 |  | 
 | 
											
												
													
														|  | -  const date = Object.keys(this.state.match.dates).find((key) =>
 |  | 
 | 
											
												
													
														|  | -      String(this.state.match.dates[key]) === this.matchDate.value
 |  | 
 | 
											
												
													
														|  | -    )
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -  placeArray.forEach((place) => {
 |  | 
 | 
											
												
													
														|  | -    let header = [
 |  | 
 | 
											
												
													
														|  | -        ['Stadtzürcher Tennismeisterschaft'],
 |  | 
 | 
											
												
													
														|  | -        [`Nenngelder für ${date}`],
 |  | 
 | 
											
												
													
														|  | -        [],
 |  | 
 | 
											
												
													
														|  | -        [`${PLACES[place] || place}`, null, '50.- oder 30.- (Junioren Jg. 1999 oder jünger)'],
 |  | 
 | 
											
												
													
														|  | -        [],
 |  | 
 | 
											
												
													
														|  | -        ['bezahlt', 'Kat.', 'Zeit', 'Name', 'Betrag bez.', 'Quittung']
 |  | 
 | 
											
												
													
														|  | -    ]
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -      // Per place
 |  | 
 | 
											
												
													
														|  | -    let payListPerPlace = []
 |  | 
 | 
											
												
													
														|  | -    this.state.match.filtered.forEach((match) => {
 |  | 
 | 
											
												
													
														|  | -      [match.Spieler1, match.Spieler2].forEach((matchPlayer) => {
 |  | 
 | 
											
												
													
														|  | -        if (!!matchPlayer & (match.Ort === place | FILTER_OFF === place)) {
 |  | 
 | 
											
												
													
														|  | -          const player = this.state.player.players.find((player) =>
 |  | 
 | 
											
												
													
														|  | -              (player.Konkurrenz === match.Konkurrenz) & (player.name === matchPlayer)
 |  | 
 | 
											
												
													
														|  | -            )
 |  | 
 | 
											
												
													
														|  | -          let paid = null
 |  | 
 | 
											
												
													
														|  | -          if (player.BezahltAm < this.matchDate.value) {
 |  | 
 | 
											
												
													
														|  | -            paid = date2s(player.BezahltAm)
 |  | 
 | 
											
												
													
														|  | -          }
 |  | 
 | 
											
												
													
														|  | -          if (player.Bezahlt) {
 |  | 
 | 
											
												
													
														|  | -            paid = 'OK'
 |  | 
 | 
											
												
													
														|  | -          }
 |  | 
 | 
											
												
													
														|  | -          let price
 |  | 
 | 
											
												
													
														|  | -          if (player.isDoubles) {
 |  | 
 | 
											
												
													
														|  | -            price = (player.isJunior ? 15 : 25) + (player.isJuniorDP ? 15 : 25)
 |  | 
 | 
											
												
													
														|  | -          } else {
 |  | 
 | 
											
												
													
														|  | -            price = player.isJunior ? 30 : 50
 |  | 
 | 
											
												
													
														|  | -          }
 |  | 
 | 
											
												
													
														|  | -          payListPerPlace.push([ paid, match.Konkurrenz, time2s(match.Datum), `(${price}.-) ${matchPlayer}` ])
 |  | 
 | 
											
												
													
														|  | -        }
 |  | 
 | 
											
												
													
														|  | -      })
 |  | 
 | 
											
												
													
														|  | -    })
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -    let footer = [
 |  | 
 | 
											
												
													
														|  | -        [],
 |  | 
 | 
											
												
													
														|  | -        ['Datum'],
 |  | 
 | 
											
												
													
														|  | -        ['Turnierleiter', null, null, 'Kassierer'],
 |  | 
 | 
											
												
													
														|  | -        ['Betrag von Spielern erhalten', null, null, 'Betrag von Turnierleiter erhalten']
 |  | 
 | 
											
												
													
														|  | -    ]
 |  | 
 | 
											
												
													
														|  | -    console.log(`Generated pay list per place ${place}:`, payListPerPlace)
 |  | 
 | 
											
												
													
														|  | -    worksheets[place] = Excel.SheetFromArray(header.concat(payListPerPlace, footer))
 |  | 
 | 
											
												
													
														|  | -    paylist.SheetNames.push(place)
 |  | 
 | 
											
												
													
														|  | -    paylist.Sheets[place] = worksheets[place]
 |  | 
 | 
											
												
													
														|  | -  })
 |  | 
 | 
											
												
													
														|  | -  Excel.saveAs(paylist, 'Zahlliste.xlsx')
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -function generateSchedule (event) {
 |  | 
 | 
											
												
													
														|  | -  event.preventDefault()
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -  const matchlist = new Excel.Workbook()
 |  | 
 | 
											
												
													
														|  | -  matchlist.SheetNames = []
 |  | 
 | 
											
												
													
														|  | -  matchlist.Sheets = {}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -  const worksheets = {}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -  let placeArray = this.state.match.places
 |  | 
 | 
											
												
													
														|  | -  if (placeArray.length > 1) {
 |  | 
 | 
											
												
													
														|  | -      // placeArray = placeArray.concat([FILTER_OFF])
 |  | 
 | 
											
												
													
														|  | -  }
 |  | 
 | 
											
												
													
														|  | -  const date = Object.keys(this.state.match.dates).find((key) =>
 |  | 
 | 
											
												
													
														|  | -      String(this.state.match.dates[key]) === this.matchDate.value
 |  | 
 | 
											
												
													
														|  | -    )
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -  placeArray.forEach(place => {
 |  | 
 | 
											
												
													
														|  | -    let header = [
 |  | 
 | 
											
												
													
														|  | -        ['Stadtzürcher Tennismeisterschaft'],
 |  | 
 | 
											
												
													
														|  | -        [`Spielplan für den ${date} (${PLACES[place] || place})`],
 |  | 
 | 
											
												
													
														|  | -        [],
 |  | 
 | 
											
												
													
														|  | -        ['Platz', 'Zeit', 'Kategorie', 'Spieler 1', '', 'Spieler 2', '', '1. Satz', '2. Satz', '3. Satz', 'WO Grund']
 |  | 
 | 
											
												
													
														|  | -    ]
 |  | 
 | 
											
												
													
														|  | -    let matchListPerPlace = this.state.match.filtered.filter((match) => (match.Ort === place | place === FILTER_OFF)).map((match) =>
 |  | 
 | 
											
												
													
														|  | -        [null, time2s(match.Datum), match.Konkurrenz, match.Spieler1, match.Spieler1Klassierung, match.Spieler2, match.Spieler2Klassierung]
 |  | 
 | 
											
												
													
														|  | -      )
 |  | 
 | 
											
												
													
														|  | -    console.log('Generated match list per place:', matchListPerPlace)
 |  | 
 | 
											
												
													
														|  | -    worksheets[place] = Excel.SheetFromArray(header.concat(matchListPerPlace))
 |  | 
 | 
											
												
													
														|  | -    matchlist.SheetNames.push(place)
 |  | 
 | 
											
												
													
														|  | -    matchlist.Sheets[place] = worksheets[place]
 |  | 
 | 
											
												
													
														|  | -  })
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -  Excel.saveAs(matchlist, 'Spielplan.xlsx')
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 |