correct display of budget used

This commit is contained in:
thschleicher 2024-01-02 11:55:49 +01:00 committed by Jakob Stornig
parent 6ee1c01d6a
commit 87640420ec
6 changed files with 14 additions and 24 deletions

View file

@ -24,10 +24,9 @@ export default function Page() {
})
}, []);
const {data, isLoading, reFetch} = useFetch({sql: "SELECT guid as category_guid, name as category_name, color as category_color FROM category WHERE type = ?", args: selectedPage === "expenses" ? ["expense"] : selectedPage === "savings" ? ["saving"] : []});
const {data, isLoading, reFetch} = useFetch({sql: "SELECT c.guid AS category_guid, c.name AS category_name, c.color AS category_color, c.type AS category_type, SUM(e.amount) as total_expenses, c.allocated_amount as allocated_amount FROM expense e RIGHT JOIN category c ON e.category_guid = c.guid WHERE c.type = ? GROUP BY c.guid", args: selectedPage === "expenses" ? ["expense"] : selectedPage === "savings" ? ["saving"] : []});
useEffect(() => {
console.log("reFetch()"); //REFETCH LOG
reFetch();
}, [selectedPage]);
@ -49,7 +48,7 @@ export default function Page() {
{isLoading ? (<LoadingSymbol/>) : (
<FlatList
data={data}
renderItem = {({item}) => <CategoryItem category={item.category_name} allocated_ammount={100} color={item.category_color} category_guid={item.category_guid} total_expenses={calculateSumOfCategory(item.guid, data)}/>}
renderItem = {({item}) => <CategoryItem category={item.category_name} allocated_amount={item.allocated_amount ?? 0} color={item.category_color} category_guid={item.category_guid} total_expenses={item.total_expenses ?? 0}/>}
keyExtractor={item => item.category_guid}
ItemSeparatorComponent={() => {
return (<View style={styles.itemSeperatorStyle}/>);
@ -60,15 +59,6 @@ export default function Page() {
);
}
const calculateSumOfCategory = (guid: string, data: {[column: string]: any;}[]): number => {
return 10;
}
const styles = StyleSheet.create({
safeAreaViewStyle: {
flex: 1,