-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMobileAppController
More file actions
149 lines (95 loc) · 5.21 KB
/
Copy pathMobileAppController
File metadata and controls
149 lines (95 loc) · 5.21 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
public class MobileAppController{
public string getdateMax(){
string dMax;
date d = date.today();
string y = string.valueof(d.year());
string m = string.valueof(d.month());
if(m.length() == 1){m = '0' + string.valueof(d.month());}
string dy = string.valueof(d.day());
if(dy.length() == 1){dy = '0' + string.valueof(d.day());}
dMax = y + '-' + m + '-' + dy;
return dMax;
}
public MobileAppController(ApexPages.StandardController controller){
//attachment = new Attachment();
}
public List<String> getYRoptions() {
List<String> options = new List<String>();
ownID = UserInfo.getUserId();
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(string.valueof(x));
}
system.debug(options);
}else{
options.add(string.valueof(yr));
}
return options;
}
public static List<Expense__c> expList {get; set;}
public static id ownID {get; set;}
@RemoteAction
public static List<Expense__c> getExpense() {
integer yrVal = date.today().year();
ownID = UserInfo.getUserId();
expList = [select id, Attachments__c, Comment__c, Name, Date__c, Ownerid, Owner.firstName, Owner.lastName, Expense_Type__c, Company__c, Total_Amount__c from Expense__c where CALENDAR_YEAR(DATE__C) =: yrVal AND OwnerId =: ownID order by Date__c DESC];
return expList;
}
@RemoteAction
public static List<Expense__c> getFilteredExp(string eType) {
integer yrVal = date.today().year();
ownID = UserInfo.getUserId();
if(eType == 'All'){
expList = [select id, Attachments__c, Comment__c, Name, Date__c, Ownerid, Owner.firstName, Owner.lastName, Expense_Type__c, Company__c, Total_Amount__c from Expense__c where CALENDAR_YEAR(DATE__C) =: yrVal AND OwnerId =: ownID order by Date__c DESC];
}else{
expList = [select id, Attachments__c, Comment__c, Name, Date__c, Ownerid, Owner.firstName, Owner.lastName, Expense_Type__c, Company__c, Total_Amount__c from Expense__c where CALENDAR_YEAR(DATE__C) =: yrVal AND OwnerId =: ownID AND Expense_Type__c =: eType order by Date__c DESC];
}
return expList;
}
@RemoteAction
public static List<Expense__c> getFilteredMonth(integer sMonth, string filterYr) {
//integer sMonth = integer.valueof(m);
integer yrVal = date.today().year();
integer sYear = integer.valueof(filterYr);
ownID = UserInfo.getUserId();
if(sMonth == 0){
expList = [select id, Attachments__c, Comment__c, Name, Date__c, Ownerid, Owner.firstName, Owner.lastName, Expense_Type__c, Company__c, Total_Amount__c from Expense__c where CALENDAR_YEAR(DATE__C) =: sYear AND OwnerId =: ownID order by Date__c DESC];
}else{
expList = [select id, Attachments__c, Comment__c, Name, Date__c, Ownerid, Owner.firstName, Owner.lastName, Expense_Type__c, Company__c, Total_Amount__c from Expense__c where CALENDAR_YEAR(DATE__C) =: sYear AND OwnerId =: ownID AND CALENDAR_MONTH(Date__c) =: sMonth order by Date__c DESC];
}
system.debug(expList);
return expList;
}
@RemoteAction
public static pageReference saveExp(id oID, string eDate, string eType, string eCompany, double eAmt, string comment){
if(oID != null){
Expense__c selExp = [select id, Attachments__c, Comment__c, Name, Date__c, Ownerid, Owner.firstName, Owner.lastName, Expense_Type__c, Company__c, Total_Amount__c from Expense__c where id =: oID];
selExp.Date__c = date.valueOf(eDate);
selExp.Expense_Type__c = eType;
selExp.Company__c = eCompany;
selExp.Total_Amount__c = eAmt;
selExp.Comment__c = comment;
system.debug(selExp);
update selExp;
}else{
Expense__c newExp = new Expense__c();
newExp.Date__c = date.valueOf(eDate);
newExp.Expense_Type__c = eType;
newExp.Company__c = eCompany;
newExp.Total_Amount__c = eAmt;
insert newExp;
}
return null;
}
@RemoteAction
public static pageReference deleteExp(id oID){
Expense__c selExp = [select id from Expense__c where id =: oID];
delete selExp;
return null;
}
}