Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nilspenzel committed Mar 11, 2025
1 parent 4a769d8 commit a359e2b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/lib/ui/AccountingView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
addSumRow: boolean
) => {
let data = [];
data.push(cols.map((col) => col.text.trim()));
data.push(cols.map((col) => col.text.join(' ')));
for (let row of rows) {
data.push(cols.map((col) => col.toTableEntry(row)));
}
Expand Down
36 changes: 21 additions & 15 deletions src/lib/ui/SortableTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}: {
rows: T[];
cols: {
text: string;
text: string[];
sort: undefined | ((r1: T, r2: T) => number);
toTableEntry: (r: T) => string | number;
}[];
Expand All @@ -36,25 +36,31 @@
};
</script>

{#snippet tableHead(text: string[], i: number, sort: boolean)}
{#if sort}
<Table.Head rowspan={text.length}>
<Button class="px-0 hover:no-underline" variant="link" onclick={() => sortAndToggle(i)}>
{#each text as line}
{line}<br />
{/each}
<ChevronsUpDown />
</Button>
</Table.Head>
{:else}
<Table.Head rowspan={text.length}>
{#each text as line}
{line}<br />
{/each}</Table.Head
>
{/if}
{/snippet}

<div class="min-w-[160vh]">
<Table.Root>
<Table.Header>
<Table.Row>
{#each cols as col, i}
{#if col.sort != undefined}
<Table.Head>
<Button
class="px-0 hover:no-underline"
variant="link"
onclick={() => sortAndToggle(i)}
>
{col.text}
<ChevronsUpDown />
</Button>
</Table.Head>
{:else}
<Table.Head>{col.text}</Table.Head>
{/if}
{@render tableHead(col.text, i, col.sort != undefined)}
{/each}
</Table.Row>
</Table.Header>
Expand Down
62 changes: 33 additions & 29 deletions src/lib/ui/tableData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type Subtractions = CompanyRow & {
};

export type Column<T> = {
text: string;
text: string[];
sort: undefined | ((r1: T, r2: T) => number);
toTableEntry: (r: T) => string | number;
};
Expand Down Expand Up @@ -64,47 +64,47 @@ const displayDuration = (duration: number) => {
};

const firstTourColAdmin: Column<TourWithRequests> = {
text: 'Unternehmen',
text: ['Unternehmen'],
sort: (a: TourWithRequests, b: TourWithRequests) => a.companyId - b.companyId,
toTableEntry: (r: TourWithRequests) => r.companyName ?? ''
};

const restTourCols = (isAdmin: boolean): Column<TourWithRequests>[] => {
return [
{
text: 'Fahrzeug',
text: ['Fahrzeug'],
sort: (a: TourWithRequests, b: TourWithRequests) => a.vehicleId - b.vehicleId,
toTableEntry: (r: TourWithRequests) => r.licensePlate ?? ''
},
{
text: 'Abfahrt ',
text: ['Abfahrt'],
sort: (t1: TourWithRequests, t2: TourWithRequests) => t1.startTime - t2.startTime,
toTableEntry: (r: TourWithRequests) => displayUnixtimeMs(r.startTime, true)
},
{
text: 'Ankunft',
text: ['Ankunft'],
sort: (t1: TourWithRequests, t2: TourWithRequests) => t1.endTime - t2.endTime,
toTableEntry: (r: TourWithRequests) => displayUnixtimeMs(r.endTime, true)
},
{
text: 'Kunden',
text: ['Kunden'],
sort: (t1: TourWithRequests, t2: TourWithRequests) =>
getCustomerCount(t1, false) - getCustomerCount(t2, false),
toTableEntry: (r: TourWithRequests) => getCustomerCount(r, false)
},
{
text: 'erschienene Kunden ',
text: ['erschienene', 'Kunden'],
sort: (t1: TourWithRequests, t2: TourWithRequests) =>
getCustomerCount(t1, true) - getCustomerCount(t2, true),
toTableEntry: (r: TourWithRequests) => getCustomerCount(r, true)
},
{
text: 'Taxameterstand ',
text: ['Taxameterstand'],
sort: (t1: TourWithRequests, t2: TourWithRequests) => (t1.fare ?? 0) - (t2.fare ?? 0),
toTableEntry: (r: TourWithRequests) => getEuroString(r.fare)
},
{
text: isAdmin ? 'Kosten ' : 'Einnahmen ',
text: isAdmin ? ['Kosten'] : ['Einnahmen'],
sort: (t1: TourWithRequests, t2: TourWithRequests) => getTourCost(t1) - getTourCost(t2),
toTableEntry: (r: TourWithRequests) => getEuroString(getTourCost(r))
}
Expand All @@ -116,52 +116,52 @@ export const tourColsCompany = restTourCols(false);

export const subtractionColsAdmin: Column<Subtractions>[] = [
{
text: 'Unternehmen',
text: ['Unternehmen'],
sort: (a: Subtractions, b: Subtractions) => a.companyId - b.companyId,
toTableEntry: (r: Subtractions) => r.companyName ?? ''
},
{
text: 'Fahrzeug',
text: ['Fahrzeug'],
sort: (a: Subtractions, b: Subtractions) => a.vehicleId - b.vehicleId,
toTableEntry: (r: Subtractions) => r.licensePlate ?? ''
},
{
text: 'Tag ',
text: ['Tag'],
sort: (a: Subtractions, b: Subtractions) => a.timestamp - b.timestamp,
toTableEntry: (r: Subtractions) => displayUnixtimeMs(r.timestamp)
},
{
text: 'Kunden',
text: ['Kunden'],
sort: (a: Subtractions, b: Subtractions) => a.customerCount - b.customerCount,
toTableEntry: (r: Subtractions) => r.customerCount
},
{
text: 'erschienene Kunden ',
text: ['erschienene', 'Kunden'],
sort: (a: Subtractions, b: Subtractions) => a.verifiedCustomerCount - b.verifiedCustomerCount,
toTableEntry: (r: Subtractions) => r.verifiedCustomerCount
},
{
text: 'Taxameterstand kumuliert ',
text: ['Taxameterstand', 'kumuliert'],
sort: (a: Subtractions, b: Subtractions) => a.taxameter - b.taxameter,
toTableEntry: (r: Subtractions) => getEuroString(r.taxameter)
},
{
text: 'Einnahmen ohne Obergrenze ',
text: ['Einnahmen', 'ohne Obergrenze'],
sort: (a: Subtractions, b: Subtractions) => a.uncapped - b.uncapped,
toTableEntry: (r: Subtractions) => getEuroString(r.uncapped)
},
{
text: 'gesetzte Verfügbarkeit',
text: ['gesetzte', 'Verfügbarkeit'],
sort: (a: Subtractions, b: Subtractions) => a.availabilityDuration - b.availabilityDuration,
toTableEntry: (r: Subtractions) => displayDuration(r.availabilityDuration)
},
{
text: 'Obergrenze',
text: ['Obergrenze'],
sort: (a: Subtractions, b: Subtractions) => a.availabilityDuration - b.availabilityDuration,
toTableEntry: (r: Subtractions) => getEuroString((r.availabilityDuration / HOUR) * CAP)
},
{
text: 'über Obergrenze',
text: ['über', 'Obergrenze'],
sort: (a: Subtractions, b: Subtractions) =>
a.uncapped -
(a.availabilityDuration / HOUR) * CAP -
Expand All @@ -170,12 +170,12 @@ export const subtractionColsAdmin: Column<Subtractions>[] = [
getEuroString(r.uncapped - (r.availabilityDuration / HOUR) * CAP)
},
{
text: 'Einnahmen mit Obergrenze ',
text: ['Einnahmen', 'mit Obergrenze'],
sort: (a: Subtractions, b: Subtractions) => a.capped - b.capped,
toTableEntry: (r: Subtractions) => getEuroString(r.capped)
},
{
text: 'Abzüge ',
text: ['Abzüge'],
sort: (a: Subtractions, b: Subtractions) => a.uncapped - a.capped - b.uncapped + b.capped,
toTableEntry: (r: Subtractions) => getEuroString(r.uncapped - r.capped)
}
Expand All @@ -185,33 +185,37 @@ export const subtractionColsCompany = subtractionColsAdmin.slice(1);

export const companyColsAdmin: Column<CompanyRow>[] = [
{
text: 'Unternehmen',
text: ['Unternehmen'],
sort: (a: CompanyRow, b: CompanyRow) => a.companyId - b.companyId,
toTableEntry: (r: CompanyRow) => r.companyName ?? ''
},
{ text: 'Kunden', sort: undefined, toTableEntry: (r: CompanyRow) => r.customerCount },
{
text: 'erschienene Kunden ',
sort: undefined,
text: ['Kunden'],
sort: (a: CompanyRow, b: CompanyRow) => a.customerCount - b.customerCount,
toTableEntry: (r: CompanyRow) => r.customerCount
},
{
text: ['erschienene', 'Kunden'],
sort: (a: CompanyRow, b: CompanyRow) => a.verifiedCustomerCount - b.verifiedCustomerCount,
toTableEntry: (r: CompanyRow) => r.verifiedCustomerCount
},
{
text: 'Taxameterstand kumuliert ',
text: ['Taxameterstand', 'kumuliert'],
sort: (a: CompanyRow, b: CompanyRow) => a.taxameter - b.taxameter,
toTableEntry: (r: CompanyRow) => getEuroString(r.taxameter)
},
{
text: 'Kosten ohne Obergrenze ',
text: ['Kosten ohne', 'Obergrenze'],
sort: (a: CompanyRow, b: CompanyRow) => a.uncapped - b.uncapped,
toTableEntry: (r: CompanyRow) => getEuroString(r.uncapped)
},
{
text: 'Kosten mit Obergrenze ',
text: ['Kosten mit Obergrenze'],
sort: (a: CompanyRow, b: CompanyRow) => a.capped - b.capped,
toTableEntry: (r: CompanyRow) => getEuroString(r.capped)
},
{
text: 'Abzüge ',
text: ['Abzüge'],
sort: (a: CompanyRow, b: CompanyRow) => a.uncapped - a.capped - b.uncapped + b.capped,
toTableEntry: (r: CompanyRow) => getEuroString(r.uncapped - r.capped)
}
Expand Down

0 comments on commit a359e2b

Please sign in to comment.