-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpReportController
More file actions
119 lines (82 loc) · 4.12 KB
/
Copy pathexpReportController
File metadata and controls
119 lines (82 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
public class expReportController{
ID ownID;
public String selYear {get; set;}
public expReportController(){
selYear = string.valueof(date.today().year());
}
public List<SelectOption> getYRoptions() {
List<SelectOption> options = new List<SelectOption>();
integer yr = date.today().year();
Expense__c exp = new Expense__c();
if([select Id, Date__c from Expense__c where ownerID =: ownID order by Date__c limit 1] != null){
exp = [select Id, Date__c from Expense__c where ownerID =: ownID order by Date__c ASC limit 1];
integer y = exp.Date__c.year();
system.debug(exp.Date__c.year());
for(integer x = yr; x >= y; x--){
options.add(new SelectOption(string.valueof(x), string.valueof(x)));
}
system.debug(options);
}else{
options.add(new SelectOption(string.valueof(yr), string.valueof(yr)));
}
return options;
}
public List<tableWrapper> getTableVal() {
ownID = UserInfo.getUserId();
List<tableWrapper> data = new List<tableWrapper>();
//double totalVal = 0;
for (AggregateResult ar : [select Expense_Type__c eType, SUM(Total_Amount__c) sAmt from Expense__c WHERE CALENDAR_YEAR(Date__c) =: integer.valueof(selYear) AND OwnerId =: ownID group by Expense_Type__c]) {
data.add(new tableWrapper(string.valueof(ar.get('eType')), double.valueof(ar.get('sAmt'))));
//totalVal += double.valueof(ar.get('sAmt'));
}
//data.add(new tableWrapper('Total', totalVal));
return data;
}
public List<tableWrapper> getMTableVal() {
ownID = UserInfo.getUserId();
Map<string, string> monthMap = new Map<string,string>();
monthMap.put('1', 'January');
monthMap.put('2', 'February');
monthMap.put('3', 'March');
monthMap.put('4', 'April');
monthMap.put('5', 'May');
monthMap.put('6', 'June');
monthMap.put('7', 'July');
monthMap.put('8', 'August');
monthMap.put('9', 'September');
monthMap.put('10', 'October');
monthMap.put('11', 'November');
monthMap.put('12', 'December');
List<tableWrapper> data = new List<tableWrapper>();
for (AggregateResult ar : [select CALENDAR_MONTH(Date__c) d, SUM(Total_Amount__c) sAmt from Expense__c WHERE CALENDAR_YEAR(Date__c) =: integer.valueof(selYear) AND OwnerId =: ownID group by CALENDAR_MONTH(Date__c) ORDER BY CALENDAR_MONTH(Date__c)]) {
data.add(new tableWrapper(monthMap.get(string.valueof(ar.get('d'))), double.valueof(ar.get('sAmt'))));
}
return data;
}
public List<tableWrapper> getCTableVal() {
ownID = UserInfo.getUserId();
List<tableWrapper> data = new List<tableWrapper>();
//double totalVal = 0;
for (AggregateResult ar : [select Company__c c, SUM(Total_Amount__c) sAmt from Expense__c WHERE CALENDAR_YEAR(Date__c) =: integer.valueof(selYear) AND OwnerId =: ownID group by Company__c order by Company__c]) {
data.add(new tableWrapper(string.valueof(ar.get('c')), double.valueof(ar.get('sAmt'))));
//totalVal += double.valueof(ar.get('sAmt'));
}
//data.add(new tableWrapper('Total', totalVal));
return data;
}
public class tableWrapper {
public string title {get; set;}
public double val {get; set;}
//This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
public tableWrapper(string c, double v) {
title = c;
val = v;
}
}
public PageReference filterYear() {
getTableVal();
getMTableVal();
getCTableVal();
return null;
}
}