-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added an endpoint for getting the costssheet and a basic table view f…
…or it
- Loading branch information
Felix Ruf
committed
Aug 9, 2023
1 parent
d0e5db5
commit 2d9ec1b
Showing
12 changed files
with
309 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ICosts } from "@/stores/costsStore"; | ||
import useApi from "./api"; | ||
|
||
/** | ||
* Performs a GET request for a list of costs | ||
*/ | ||
export default async function getCosts() { | ||
const { error, response: costs, request } = useApi<ICosts>( | ||
'GET', | ||
'api/costs' | ||
); | ||
|
||
await request(); | ||
|
||
return { error, costs }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<template> | ||
<router-link | ||
:to="'/costs'" | ||
class="flex flex-row items-center gap-2" | ||
> | ||
<CurrencyEuroIcon class="h-6 w-6" /> | ||
<span>{{ t('costs.cashRegister') }}</span> | ||
</router-link> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { CurrencyEuroIcon } from '@heroicons/vue/outline'; | ||
import { useI18n } from 'vue-i18n'; | ||
const { t } = useI18n(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<template> | ||
<div class="mb-8 grid w-full grid-cols-3 gap-3 sm:grid-rows-[minmax(0,1fr)_30px] min-[900px]:grid-cols-[minmax(0,2fr)_minmax(0,1fr)] min-[900px]:gap-1"> | ||
<h2 class="col-span-3 col-start-1 row-span-1 row-start-1 m-0 w-full self-center justify-self-start max-[380px]:text-[24px] min-[900px]:col-span-1"> | ||
{{ t('costs.header') }} | ||
</h2> | ||
<CashRegisterLink | ||
class="col-span-3 row-start-2 justify-self-center sm:col-span-1 sm:col-start-1 sm:justify-self-start min-[900px]:row-start-2" | ||
/> | ||
<InputLabel | ||
v-model="filter" | ||
:label-text="t('costs.search')" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useI18n } from 'vue-i18n'; | ||
import CashRegisterLink from './CashRegisterLink.vue'; | ||
import InputLabel from '../misc/InputLabel.vue'; | ||
import { computed } from 'vue'; | ||
const { t } = useI18n(); | ||
const props = defineProps<{ | ||
modelValue: string | ||
}>(); | ||
const emit = defineEmits(['update:modelValue']); | ||
const filter = computed({ | ||
get() { | ||
return props.modelValue; | ||
}, | ||
set(filter) { | ||
emit('update:modelValue', filter); | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<template> | ||
<Table | ||
:labels="columnNames" | ||
:header-text-left="false" | ||
> | ||
<tr | ||
v-for="[username, costs] in filteredUsers" | ||
:key="username" | ||
class="max-h-[62px] border-b-2 border-gray-200 text-right text-[12px] xl:text-[18px]" | ||
> | ||
<td class="py-2 text-left"> | ||
{{ `${costs.name}, ${costs.firstName}` }} | ||
</td> | ||
<td> | ||
{{ new Intl.NumberFormat(locale, { style: 'currency', currency: 'EUR' }).format(costs.costs['earlier']) }} | ||
</td> | ||
<td | ||
v-for="column in Object.keys(CostsState.columnNames)" | ||
:key="`${String(column)}_${username}`" | ||
> | ||
{{ new Intl.NumberFormat(locale, { style: 'currency', currency: 'EUR' }).format(costs.costs[column]) }} | ||
</td> | ||
<td> | ||
{{ new Intl.NumberFormat(locale, { style: 'currency', currency: 'EUR' }).format(costs.costs['total']) }} | ||
</td> | ||
<td> | ||
Actions to be implemented | ||
</td> | ||
</tr> | ||
</Table> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import Table from '@/components/misc/Table.vue'; | ||
import { useCosts } from '@/stores/costsStore'; | ||
import { computed } from 'vue'; | ||
import { useI18n } from 'vue-i18n'; | ||
const { t, locale } = useI18n(); | ||
const { CostsState, getColumnNames } = useCosts(); | ||
const props = defineProps<{ | ||
filter: string | ||
}>(); | ||
const columnNames = computed(() => ['Name', t('costs.table.earlier'), ...getColumnNames(locale.value), t('costs.table.total'), t('costs.table.actions')]); | ||
const filteredUsers = computed(() => { | ||
if (props.filter === '') { | ||
return Object.entries(CostsState.users) | ||
} | ||
const filterStrings = props.filter.split(/[\s,.]+/).map(filterStr => filterStr.toLowerCase()); | ||
const regex = createRegexForFilter(filterStrings); | ||
return Object.entries(CostsState.users).filter(user => { | ||
const [key, value] = user; | ||
const searchStrings = [value.firstName, value.name].join(' '); | ||
return regex.test(searchStrings); | ||
}); | ||
}); | ||
function createRegexForFilter(filterStrings: string[]): RegExp { | ||
let regexStr = ''; | ||
for (let i = 0; i < filterStrings.length - 1; i++) { | ||
regexStr += `(${filterStrings[i]}.*${filterStrings[i+1]})?`; | ||
regexStr += `(${filterStrings[i+1]}.*${filterStrings[i]})?`; | ||
} | ||
regexStr += `(${filterStrings.join('|')})`; | ||
if (filterStrings.length > 1) { | ||
regexStr = '^' + regexStr + '?$'; | ||
} | ||
return new RegExp(regexStr, 'i'); | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import getCosts from "@/api/getCosts"; | ||
import { DateTime } from "@/api/getDashboardData"; | ||
import { isResponseObjectOkay } from "@/api/isResponseOkay"; | ||
import { Dictionary } from "types/types"; | ||
import { reactive, readonly } from "vue"; | ||
import { translateMonth } from "@/tools/localeHelper"; | ||
|
||
export interface ICosts { | ||
columnNames: Dictionary<DateTime>, | ||
users: Dictionary<UserCost> | ||
} | ||
|
||
interface UserCost { | ||
name: string, | ||
firstName: string, | ||
hidden: boolean, | ||
costs: Dictionary<number> | ||
} | ||
|
||
interface ICostsState extends ICosts { | ||
error: string, | ||
isLoading: boolean | ||
} | ||
|
||
const CostsState = reactive<ICostsState>({ | ||
columnNames: {}, | ||
users: {}, | ||
error: "", | ||
isLoading: false | ||
}); | ||
|
||
function isCosts(costs: ICosts): costs is ICosts { | ||
|
||
if (costs.columnNames !== null && costs.columnNames !== undefined && costs.users !== null && costs.users !== undefined) { | ||
const cost = Object.values(costs.users)[0]; | ||
const column = Object.values(costs.columnNames)[0]; | ||
|
||
return ( | ||
cost !== null && | ||
cost !== undefined && | ||
typeof (cost as UserCost).name === 'string' && | ||
typeof (cost as UserCost).firstName === 'string' && | ||
typeof (cost as UserCost).hidden === 'boolean' && | ||
(cost as UserCost).costs !== undefined && | ||
(cost as UserCost).costs !== null && | ||
Object.keys(cost).length === 4 && | ||
typeof (column as DateTime).date === 'string' && | ||
typeof (column as DateTime).timezone === 'string' && | ||
typeof (column as DateTime).timezone_type === 'number' | ||
); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
export function useCosts() { | ||
|
||
async function fetchCosts() { | ||
CostsState.isLoading = true; | ||
const { error, costs } = await getCosts(); | ||
|
||
if (isResponseObjectOkay(error, costs, isCosts) === true) { | ||
CostsState.columnNames = costs.value.columnNames; | ||
CostsState.users = costs.value.users; | ||
CostsState.error = ''; | ||
} else { | ||
CostsState.error = 'Error on fetching Costs'; | ||
} | ||
CostsState.isLoading = false; | ||
} | ||
|
||
function getColumnNames(locale: string) { | ||
return Object.values(CostsState.columnNames).map(dateTime => { | ||
return translateMonth(dateTime, locale); | ||
}); | ||
} | ||
|
||
return { | ||
CostsState: readonly(CostsState), | ||
fetchCosts, | ||
getColumnNames | ||
} | ||
} |
Oops, something went wrong.