diff --git a/app/(tabs)/budget/_layout.tsx b/app/(tabs)/budget/_layout.tsx index e826f6b..5c62492 100644 --- a/app/(tabs)/budget/_layout.tsx +++ b/app/(tabs)/budget/_layout.tsx @@ -8,7 +8,9 @@ export default function _Layout() { headerShown: false }}> - + ); } \ No newline at end of file diff --git a/app/(tabs)/budget/index.tsx b/app/(tabs)/budget/index.tsx index 8e53cc9..1027f6d 100644 --- a/app/(tabs)/budget/index.tsx +++ b/app/(tabs)/budget/index.tsx @@ -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 ? () : ( } + renderItem = {({item}) => } keyExtractor={item => item.category_guid} ItemSeparatorComponent={() => { return (); @@ -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, diff --git a/app/(tabs)/home/index.tsx b/app/(tabs)/home/index.tsx index 82d03cf..6ba2200 100644 --- a/app/(tabs)/home/index.tsx +++ b/app/(tabs)/home/index.tsx @@ -109,7 +109,7 @@ export default function Page() { } - renderItem = {({item}) => } + renderItem = {({item}) => } keyExtractor={item => item.expense_guid} ItemSeparatorComponent={() => { return (); diff --git a/app/(tabs)/stats/index.tsx b/app/(tabs)/stats/index.tsx index 7db4051..9dd775a 100644 --- a/app/(tabs)/stats/index.tsx +++ b/app/(tabs)/stats/index.tsx @@ -15,8 +15,6 @@ export default function Page() { } }); - - return ( { @@ -37,7 +35,7 @@ export default function Page() { }}>Init Database { - addCategory("Category", "green", "expense").then(() => { + addCategory("Category", "green", "expense", 500).then(() => { const getCategoryQuery: Query = {sql: "SELECT guid FROM category", args: []}; executeQuery(getCategoryQuery).then((result) => { if("rows" in result[0]) { @@ -49,7 +47,7 @@ export default function Page() { }}>Add new Category Expense { - addCategory("Category", "yellow", "saving").then(() => { + addCategory("Category", "yellow", "saving", 420).then(() => { const getCategoryQuery: Query = {sql: "SELECT guid FROM category", args: []}; executeQuery(getCategoryQuery).then((result) => { if("rows" in result[0]) { diff --git a/components/budget/categoryItem.tsx b/components/budget/categoryItem.tsx index 4d1d9fb..e651caf 100644 --- a/components/budget/categoryItem.tsx +++ b/components/budget/categoryItem.tsx @@ -5,7 +5,7 @@ import CustomCard from "../common/CustomCard"; export type CategoryItemProps = { category: string, color: ColorValue, - allocated_ammount: number, + allocated_amount: number, total_expenses: number, category_guid: string, } @@ -14,7 +14,7 @@ const CategoryItem = (properties: CategoryItemProps) => { const { colors } = useTheme(); - const subText = `${properties.total_expenses} / ${properties.allocated_ammount} €`; + const subText = `${properties.total_expenses} / ${properties.allocated_amount} €`; return ( diff --git a/services/database.ts b/services/database.ts index 404fa0f..9247fe4 100644 --- a/services/database.ts +++ b/services/database.ts @@ -24,7 +24,7 @@ export const initDatabase = async () => { } }; -export const addCategory = async (name: string, color: string, type: string) => { +export const addCategory = async (name: string, color: string, type: string, allocated_amount: number) => { //needs user input validation for type and color (should be validated by this function) @@ -32,8 +32,8 @@ export const addCategory = async (name: string, color: string, type: string) => try { await db.transactionAsync(async (tx) => { - await tx.executeSqlAsync("INSERT INTO category (guid, name, color, type) VALUES (?, ?, ?, ?);", - [UUID.toString(), name, color, type] + await tx.executeSqlAsync("INSERT INTO category (guid, name, color, type, allocated_amount) VALUES (?, ?, ?, ?, ?);", + [UUID.toString(), name, color, type, allocated_amount] ); }); } catch (error) { @@ -42,7 +42,7 @@ export const addCategory = async (name: string, color: string, type: string) => } } -export const addExpense = async (name: string, category_guid: string,datetime: string, amount: number) => { +export const addExpense = async (name: string, category_guid: string, datetime: string, amount: number) => { //needs user input validation for type and color (should be validated by this function)