|
@@ -1,11 +1,10 @@
|
|
|
import React from 'react'
|
|
|
-import XLSX from 'xlsx-style'
|
|
|
+import XLSX from 'xlsx'
|
|
|
import PlayerList from './player/player-list'
|
|
|
import MatchList from './match/match-list'
|
|
|
import Stats from './stats/stats'
|
|
|
-import FileSaver from 'file-saver'
|
|
|
-import Workbook from 'xlsx-workbook'
|
|
|
-
|
|
|
+import { SheetFromArray, Workbook, saveAs } from './excel/excel'
|
|
|
+
|
|
|
class App extends React.Component {
|
|
|
constructor () {
|
|
|
super()
|
|
@@ -28,7 +27,8 @@ class App extends React.Component {
|
|
|
this.generatePlayerList = this.generatePlayerList.bind(this)
|
|
|
this.generateCalendar = this.generateCalendar.bind(this)
|
|
|
this.filterData = this.filterData.bind(this)
|
|
|
- this.generateExcel = this.generateExcel.bind(this)
|
|
|
+ this.generateSchedule = this.generateSchedule.bind(this)
|
|
|
+ this.generatePayTable = this.generatePayTable.bind(this)
|
|
|
}
|
|
|
|
|
|
componentDidMount () {
|
|
@@ -129,38 +129,112 @@ class App extends React.Component {
|
|
|
const filters = {
|
|
|
date: this.date.value
|
|
|
}
|
|
|
+ this.generateStats()
|
|
|
this.setState({ filters })
|
|
|
}
|
|
|
|
|
|
- generateExcel (event) {
|
|
|
+ generateSchedule (event) {
|
|
|
event.preventDefault()
|
|
|
|
|
|
- const wopts = {bookType: 'xlsx', bookSST: false, type: 'binary'}
|
|
|
-
|
|
|
- const matchlist = new Workbook.Workbook()
|
|
|
+ const matchlist = new Workbook()
|
|
|
matchlist.SheetNames = []
|
|
|
matchlist.Sheets = {}
|
|
|
- console.log(matchlist)
|
|
|
- const worksheets = {}
|
|
|
|
|
|
+ const worksheets = {}
|
|
|
const placeArray = this.state.stats.matchPlaces.concat(['Alle'])
|
|
|
+
|
|
|
placeArray.forEach((place) => {
|
|
|
- worksheets[place] = matchlist.add(place)
|
|
|
+ let filter = this.state.filters.date
|
|
|
+ let header = [
|
|
|
+ [`Spielplan für den ${filter} (${place})`],
|
|
|
+ [],
|
|
|
+ ['Ort', 'Zeit', 'Kategorie', 'Spieler 1', '', 'Spieler 2', '', '1. Satz', '2. Satz', '3. Satz', 'WO Grund']
|
|
|
+ ]
|
|
|
+ let matchListPerPlace = this.state.matches.filter((match) => {
|
|
|
+ return (match[1] === filter | filter === 'Alle') & (match[0] === place | place === 'Alle')
|
|
|
+ }).map((match) =>
|
|
|
+ [match[0], match[2], match[3], match[4], match[5], match[6], match[7]]
|
|
|
+ )
|
|
|
+ console.log(matchListPerPlace)
|
|
|
+ worksheets[place] = SheetFromArray(header.concat(matchListPerPlace))
|
|
|
matchlist.SheetNames.push(place)
|
|
|
matchlist.Sheets[place] = worksheets[place]
|
|
|
})
|
|
|
- console.log(placeArray, worksheets, matchlist)
|
|
|
-
|
|
|
- const wbout = XLSX.write(matchlist, wopts)
|
|
|
- function s2ab (s) {
|
|
|
- const buf = new ArrayBuffer(s.length)
|
|
|
- const view = new Uint8Array(buf)
|
|
|
- for (let i = 0; i !== s.length; ++i) {
|
|
|
- view[i] = s.charCodeAt(i) && 0xFF
|
|
|
+ console.log(matchlist)
|
|
|
+
|
|
|
+ saveAs(matchlist, 'Spielerliste.xlsx')
|
|
|
+ }
|
|
|
+
|
|
|
+ generatePayTable (event) {
|
|
|
+ event.preventDefault()
|
|
|
+
|
|
|
+ const paylist = new Workbook()
|
|
|
+ paylist.SheetNames = []
|
|
|
+ paylist.Sheets = {}
|
|
|
+
|
|
|
+ const worksheets = {}
|
|
|
+ const placeArray = this.state.stats.matchPlaces.concat(['Alle'])
|
|
|
+
|
|
|
+ const payerList = {}
|
|
|
+ this.state.matches.forEach((match) => {
|
|
|
+ if (!!match[4] & !payerList.hasOwnProperty(`${match[3]} ${match[4]}`)) {
|
|
|
+ let foundPlayer = this.state.players.find((player) => {
|
|
|
+ if (!!player[24]) {
|
|
|
+ return (`${player[5]} ${player[6]} / ${player[24]} ${player[25]}` === match[4]) & (match[3] === player[0].replace(/\s+/g, ' '))
|
|
|
+ } else {
|
|
|
+ return (`${player[5]} ${player[6]}` === match[4]) & (match[3] === player[0].replace(/\s+/g, ' '))
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (!foundPlayer) {
|
|
|
+ console.log(foundPlayer, match)
|
|
|
+ throw Error('Player 4 not found. This is an error!')
|
|
|
+ }
|
|
|
+ payerList[`${match[3]} ${match[4]}`] = [match[0], match[1], match[2], foundPlayer[31]]
|
|
|
}
|
|
|
- return buf
|
|
|
- }
|
|
|
- FileSaver.saveAs(new Blob([s2ab(wbout)], {type: ''}), 'Spielliste.xlsx')
|
|
|
+ if (!!match[6] & !payerList.hasOwnProperty(`${match[3]} ${match[6]}`)) {
|
|
|
+ let foundPlayer = this.state.players.find((player) => {
|
|
|
+ if (!!player[24]) {
|
|
|
+ return (`${player[5]} ${player[6]} / ${player[24]} ${player[25]}` === match[6]) & (match[3] === player[0].replace(/\s+/g, ' '))
|
|
|
+ } else {
|
|
|
+ return (`${player[5]} ${player[6]}` === match[6]) & (match[3] === player[0].replace(/\s+/g, ' '))
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (!foundPlayer) {
|
|
|
+ console.log(foundPlayer, match)
|
|
|
+ throw Error('Player 6 not found. This is an error!')
|
|
|
+ }
|
|
|
+ payerList[`${match[3]} ${match[6]}`] = [match[0], match[1], match[2], foundPlayer[31]]
|
|
|
+ }
|
|
|
+ })
|
|
|
+ console.log(payerList)
|
|
|
+
|
|
|
+ placeArray.forEach((place) => {
|
|
|
+ let filter = this.state.filters.date
|
|
|
+ let header = [
|
|
|
+ [`Zahlliste für den ${filter} (${place})`],
|
|
|
+ [],
|
|
|
+ ['bereits bez.', 'Kategorie', 'Name', 'Betrag bez.', 'Quittung abgeben']
|
|
|
+ ]
|
|
|
+
|
|
|
+ let payListPerPlace = []
|
|
|
+ this.state.matches.filter((match) => {
|
|
|
+ return (match[1] === filter | filter === 'Alle') & (match[0] === place | place === 'Alle')
|
|
|
+ }).forEach((match) => {
|
|
|
+ if (!!match[4]) {
|
|
|
+ payListPerPlace.push(match)
|
|
|
+ }
|
|
|
+ if (!!match[6]) {
|
|
|
+ payListPerPlace.push(match)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ console.log(payListPerPlace)
|
|
|
+ worksheets[place] = SheetFromArray(header.concat(payListPerPlace))
|
|
|
+ paylist.SheetNames.push(place)
|
|
|
+ paylist.Sheets[place] = worksheets[place]
|
|
|
+ })
|
|
|
+ console.log(paylist)
|
|
|
+
|
|
|
+ saveAs(paylist, 'Zahlliste.xlsx')
|
|
|
}
|
|
|
|
|
|
render () {
|
|
@@ -174,11 +248,12 @@ class App extends React.Component {
|
|
|
<label htmlFor='Date'>Datum</label>
|
|
|
<select ref={(input) => { this.date = input }} onChange={this.filterData}>
|
|
|
<option>Alle</option>
|
|
|
- {this.state.stats.matchDates.map((date) => (
|
|
|
- <option>{date}</option>
|
|
|
+ {this.state.stats.matchDates.map((date, key) => (
|
|
|
+ <option key={key}>{date}</option>
|
|
|
))}
|
|
|
</select>
|
|
|
- <button onClick={this.generateExcel}>Excel-Files generieren.</button>
|
|
|
+ <button onClick={this.generateSchedule} disabled={!this.state.matches.length}>Spielliste generieren</button>
|
|
|
+ <button onClick={this.generatePayTable} disabled={(!this.state.matches.length | !this.state.players.length)}>Zahlliste generieren</button>
|
|
|
</form>
|
|
|
<Stats stats={this.state.stats} />
|
|
|
<PlayerList players={this.state.players} />
|