|
@@ -4,8 +4,10 @@ import { ScrollView } from 'react-native-gesture-handler';
|
4
|
4
|
import { sqlite_exec_query } from '../db/query';
|
5
|
5
|
import DepenseListEntry from './depense_list_entry';
|
6
|
6
|
import DayList from './list/day_list';
|
|
7
|
+import WeekList from './list/week_list';
|
7
|
8
|
|
8
|
9
|
var getDaysArray = function(s,e) {for(var a=[],d=new Date(s);d<=e;d.setDate(d.getDate()+1)){ a.push(new Date(d));}return a;};
|
|
10
|
+var getWeek=function(i_date){return Math.ceil(((i_date-new Date(i_date.getFullYear(),0,1)+86400000)/86400000)/7)}
|
9
|
11
|
|
10
|
12
|
function DepensesList(props)
|
11
|
13
|
{
|
|
@@ -35,27 +37,113 @@ function DepensesList(props)
|
35
|
37
|
let oldestDate = new Date(oldest_depense.date);
|
36
|
38
|
|
37
|
39
|
let days = getDaysArray(oldestDate, curDate ).reverse();
|
38
|
|
- let days_disp = {};
|
39
|
|
- days.forEach( (day) => {
|
40
|
|
- // get depenses that are on the current day
|
41
|
|
- var depenses_day = depenses.filter( obj => {return new Date(obj.date).getDate() == day.getDate()} )
|
42
|
|
- content.push(
|
43
|
|
- <DayList
|
44
|
|
- dailyObjective={props.dailyObjective}
|
45
|
|
- fetchDepenses={() => preventFetchDepenses(false)}
|
46
|
|
- key={"day_list_"+day.toDateString()}
|
47
|
|
- date={day}
|
48
|
|
- depenses={depenses_day}/>)
|
49
|
|
- });
|
50
|
|
- }
|
|
40
|
+ let data = [];
|
|
41
|
+ let renderItem = null;
|
|
42
|
+ switch(props.durationMode)
|
|
43
|
+ {
|
|
44
|
+ case "days":
|
|
45
|
+ days.forEach( (day) => {
|
|
46
|
+ // get depenses that are on the current day
|
|
47
|
+ var depenses_day = depenses.filter( obj => {
|
|
48
|
+ var tpDate = new Date(obj.date);
|
|
49
|
+ return tpDate.getFullYear() == day.getFullYear() && tpDate.getMonth() == day.getMonth() && tpDate.getDate() == day.getDate()
|
|
50
|
+ } )
|
|
51
|
+
|
|
52
|
+ data.push(
|
|
53
|
+ {
|
|
54
|
+ date: day,
|
|
55
|
+ depenses: depenses_day,
|
|
56
|
+ dailyObjective: props.dailyObjective,
|
|
57
|
+ id: "day_"+day.toISOString()
|
|
58
|
+ })
|
|
59
|
+
|
|
60
|
+ });
|
|
61
|
+
|
|
62
|
+ renderItem = ({item}) =>(
|
|
63
|
+ <DayList
|
|
64
|
+ dailyObjective={props.dailyObjective}
|
|
65
|
+ fetchDepenses={() => preventFetchDepenses(false)}
|
|
66
|
+ date={item.date}
|
|
67
|
+ depenses={item.depenses}/>
|
|
68
|
+ );
|
|
69
|
+
|
|
70
|
+ content = (
|
|
71
|
+ <FlatList
|
|
72
|
+ data={data}
|
|
73
|
+ renderItem={renderItem}
|
|
74
|
+ keyExtractor={item => item.id}/>
|
|
75
|
+ )
|
|
76
|
+ break;
|
|
77
|
+ case "weeks":
|
|
78
|
+ // dont forget the list of days is ordered latest to oldest
|
|
79
|
+ let week_number = getWeek(days[0]);
|
|
80
|
+ let week = {
|
|
81
|
+ id:week_number+"_"+days[0].getFullYear(),
|
|
82
|
+ days: [],
|
|
83
|
+ number: week_number,
|
|
84
|
+ }
|
|
85
|
+ data.push(week);
|
|
86
|
+ days.forEach( (day) => {
|
|
87
|
+ week_number = getWeek(day);
|
|
88
|
+ console.log("\n\n");
|
|
89
|
+ if( week_number+"_"+day.getFullYear() == week.id)
|
|
90
|
+ week.days.push(
|
|
91
|
+ {
|
|
92
|
+ date:day,
|
|
93
|
+ expenses: depenses.filter( obj => {
|
|
94
|
+ var tpDate = new Date(obj.date);
|
|
95
|
+ return tpDate.getFullYear() == day.getFullYear() && tpDate.getMonth() == day.getMonth() && tpDate.getDate() == day.getDate()
|
|
96
|
+ } )
|
|
97
|
+ });
|
|
98
|
+ else
|
|
99
|
+ {
|
|
100
|
+ week = {
|
|
101
|
+ id:week_number+"_"+day.getFullYear(),
|
|
102
|
+ days: [
|
|
103
|
+ {
|
|
104
|
+ date:day,
|
|
105
|
+ expenses: depenses.filter( obj => {
|
|
106
|
+ var tpDate = new Date(obj.date);
|
|
107
|
+ return tpDate.getFullYear() == day.getFullYear() && tpDate.getMonth() == day.getMonth() && tpDate.getDate() == day.getDate()
|
|
108
|
+ } )
|
|
109
|
+ }
|
|
110
|
+ ],
|
|
111
|
+ number: week_number,
|
|
112
|
+ }
|
|
113
|
+ data.push(week);
|
|
114
|
+ }
|
|
115
|
+ });
|
|
116
|
+
|
|
117
|
+ renderItem = ({item}) =>(
|
|
118
|
+ <WeekList
|
|
119
|
+ dailyObjective={props.dailyObjective}
|
|
120
|
+ days={item.days}
|
|
121
|
+ number={item.number}
|
|
122
|
+ fetchDepenses={() => preventFetchDepenses(false)}
|
|
123
|
+ />
|
|
124
|
+ );
|
|
125
|
+
|
|
126
|
+ content = (
|
|
127
|
+ <FlatList
|
|
128
|
+ data={data}
|
|
129
|
+ renderItem={renderItem}
|
|
130
|
+ keyExtractor={item => item.id}/>
|
|
131
|
+ )
|
|
132
|
+ break;
|
|
133
|
+ default:
|
|
134
|
+ content = <Text> This does not work yet :(</Text>
|
|
135
|
+ }
|
|
136
|
+
|
|
137
|
+ }else
|
|
138
|
+ content = <Text> Start adding expenses ! </Text>
|
51
|
139
|
|
52
|
140
|
|
53
|
141
|
return(
|
54
|
|
- <View>
|
55
|
|
- <ScrollView>
|
|
142
|
+ <SafeAreaView >
|
|
143
|
+ <View>
|
56
|
144
|
{content}
|
57
|
|
- </ScrollView>
|
58
|
|
- </View>
|
|
145
|
+ </View>
|
|
146
|
+ </SafeAreaView >
|
59
|
147
|
)
|
60
|
148
|
}
|
61
|
149
|
|