|
12 | 12 | import { CalendarDate } from '@internationalized/date';
|
13 | 13 | import { groupBy } from '$lib/util/groupBy';
|
14 | 14 | import {
|
15 |
| - companyCols, |
| 15 | + companyColsAdmin, |
| 16 | + companyColsCompany, |
16 | 17 | getEuroString,
|
17 |
| - subtractionCols, |
18 |
| - tourCols, |
| 18 | + subtractionColsAdmin, |
| 19 | + subtractionColsCompany, |
| 20 | + tourColsAdmin, |
| 21 | + tourColsCompany, |
19 | 22 | type Column,
|
20 | 23 | type CompanyRow,
|
21 | 24 | type Subtractions
|
|
44 | 47 | earliestTime: UnixtimeMs;
|
45 | 48 | } = $props();
|
46 | 49 |
|
47 |
| - let currentRowsToursTable: TourWithRequests[] = $state(tours); |
48 |
| - let currentRowsSubtractionsTable: Subtractions[] = $state(companyCostsPerDay); |
49 |
| -
|
50 | 50 | const updateCompanySums = (subtractionRows: Subtractions[]) => {
|
51 | 51 | const accumulatedCompanyRowEntries = (arr: (Subtractions | CompanyRow)[]) => {
|
52 | 52 | return arr.reduce(
|
|
69 | 69 | }
|
70 | 70 | );
|
71 | 71 | };
|
| 72 | +
|
72 | 73 | const costsPerCompany = groupBy(
|
73 | 74 | subtractionRows,
|
74 | 75 | (c) => c.companyId,
|
|
80 | 81 | return;
|
81 | 82 | }
|
82 | 83 | const accumulated = accumulatedCompanyRowEntries(arr);
|
83 |
| - newCompanyRows.push({ ...accumulated, companyName: arr[0].companyName, companyId }); |
| 84 | + if (isAdmin) { |
| 85 | + newCompanyRows.push({ ...accumulated, companyName: arr[0].companyName, companyId }); |
| 86 | + } else { |
| 87 | + newCompanyRows.push({ ...accumulated, companyId }); |
| 88 | + } |
84 | 89 | });
|
85 | 90 | if (newCompanyRows.length === 0) {
|
86 |
| - return; |
| 91 | + return []; |
87 | 92 | }
|
88 | 93 | if (isAdmin) {
|
89 | 94 | newCompanyRows.push({
|
|
94 | 99 | }
|
95 | 100 | return newCompanyRows;
|
96 | 101 | };
|
97 |
| - let currentCompanyRows: CompanyRow[] = $state(updateCompanySums(companyCostsPerDay)!); |
| 102 | +
|
| 103 | + let currentRowsToursTable: TourWithRequests[] = $state(tours); |
| 104 | + let currentRowsSubtractionsTable: Subtractions[] = $state(companyCostsPerDay); |
| 105 | + let currentCompanyRows: CompanyRow[] = $state(updateCompanySums(companyCostsPerDay)); |
98 | 106 |
|
99 | 107 | const getNewSum = (rows: Subtractions[]) => {
|
100 | 108 | let newSum = 0;
|
|
135 | 143 | $effect(() => {
|
136 | 144 | currentRowsToursTable = getNewRows(tourFilters, tours);
|
137 | 145 | const subtractionRows = getNewRows(subtractionFilters, companyCostsPerDay);
|
138 |
| - currentCompanyRows = updateCompanySums(subtractionRows)!; |
| 146 | + currentCompanyRows = updateCompanySums(subtractionRows); |
139 | 147 | currentRowsSubtractionsTable = subtractionRows;
|
140 | 148 | });
|
141 | 149 |
|
|
203 | 211 |
|
204 | 212 | const csvExport = <T,>(rows: T[], cols: Column<T>[], filename: string, addSumRow: boolean) => {
|
205 | 213 | let data = [];
|
206 |
| - data.push(cols.map((col) => col.text)); |
| 214 | + data.push(cols.map((col) => col.text.trim())); |
207 | 215 | for (let row of rows) {
|
208 | 216 | data.push(cols.map((col) => col.toTableEntry(row)));
|
209 | 217 | }
|
|
220 | 228 | saveAs(blob, filename);
|
221 | 229 | };
|
222 | 230 |
|
223 |
| - csvExport(tourRows, tourCols, filename + '_tour.csv', false); |
224 |
| - csvExport(subtractionRows, subtractionCols, filename + '_abzuege.csv', true); |
| 231 | + csvExport(tourRows, isAdmin ? tourColsAdmin : tourColsCompany, filename + '_tour.csv', false); |
| 232 | + csvExport( |
| 233 | + subtractionRows, |
| 234 | + isAdmin ? subtractionColsAdmin : subtractionColsCompany, |
| 235 | + filename + '_abzuege.csv', |
| 236 | + true |
| 237 | + ); |
225 | 238 | };
|
226 | 239 |
|
227 | 240 | let tables = [
|
|
241 | 254 | </script>
|
242 | 255 |
|
243 | 256 | {#snippet tourTable()}
|
244 |
| - <SortableTable rows={currentRowsToursTable} cols={tourCols} {isAdmin} /> |
| 257 | + <SortableTable |
| 258 | + rows={currentRowsToursTable} |
| 259 | + cols={isAdmin ? tourColsAdmin : tourColsCompany} |
| 260 | + {isAdmin} |
| 261 | + /> |
245 | 262 | {/snippet}
|
246 | 263 |
|
247 | 264 | {#snippet subtractionTable()}
|
248 |
| - <SortableTable rows={currentRowsSubtractionsTable} cols={subtractionCols} {isAdmin} /> |
| 265 | + <SortableTable |
| 266 | + rows={currentRowsSubtractionsTable} |
| 267 | + cols={isAdmin ? subtractionColsAdmin : subtractionColsCompany} |
| 268 | + {isAdmin} |
| 269 | + /> |
249 | 270 | {/snippet}
|
250 | 271 |
|
251 | 272 | {#snippet companyTable()}
|
252 |
| - <SortableTable rows={currentCompanyRows} cols={companyCols} {isAdmin} /> |
| 273 | + <SortableTable |
| 274 | + rows={currentCompanyRows} |
| 275 | + cols={isAdmin ? companyColsAdmin : companyColsCompany} |
| 276 | + {isAdmin} |
| 277 | + /> |
253 | 278 | {/snippet}
|
254 | 279 |
|
255 | 280 | {#snippet filterOptions()}
|
|
0 commit comments