Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mytime
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Narendar Vakiti
mytime
Commits
324a252b
Unverified
Commit
324a252b
authored
Sep 05, 2018
by
mshaik-nisum-com
Committed by
GitHub
Sep 05, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #182 from nisum-inc/FEATURE/Get_LoginReport_Based_On_DateTime
MT-175:Login Report Based On Selected Time and Date
parents
856aa6c9
337f8970
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
108 additions
and
87 deletions
+108
-87
AttendanceController.java
...ava/com/nisum/mytime/controller/AttendanceController.java
+12
-18
AttendanceServiceImpl.java
.../java/com/nisum/mytime/service/AttendanceServiceImpl.java
+3
-6
EmployeeDataService.java
...in/java/com/nisum/mytime/service/EmployeeDataService.java
+58
-59
UserService.java
src/main/java/com/nisum/mytime/service/UserService.java
+4
-0
UserServiceImpl.java
src/main/java/com/nisum/mytime/service/UserServiceImpl.java
+8
-1
PdfReportGenerator.java
src/main/java/com/nisum/mytime/utils/PdfReportGenerator.java
+21
-1
ReportsController.js
src/main/webapp/WEB-INF/controllers/ReportsController.js
+2
-2
No files found.
src/main/java/com/nisum/mytime/controller/AttendanceController.java
View file @
324a252b
package
com
.
nisum
.
mytime
.
controller
;
import
java.sql.SQLException
;
import
java.text.ParseException
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -46,24 +47,6 @@ public class AttendanceController {
return
new
ResponseEntity
<>(
message
,
HttpStatus
.
OK
);
}
@RequestMapping
(
value
=
"employeeLoginReportBasedOnDateTime"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
ResponseEntity
<
List
<
EmpLoginData
>>
employeeLoginReportBasedOnDateTime
(
@RequestParam
(
"empId"
)
long
id
,
@RequestParam
(
"fromDate"
)
String
fromDate
,
@RequestParam
(
"toDate"
)
String
toDate
,
@RequestParam
(
"fromTime"
)
String
fromTime
,
@RequestParam
(
"toTime"
)
String
toTime
)
throws
MyTimeException
{
List
<
EmpLoginData
>
message
=
new
ArrayList
<>();
try
{
message
=
attendanceService
.
employeeLoginReportBasedOnDateTime
(
id
,
fromDate
,
toDate
,
fromTime
,
toTime
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
new
ResponseEntity
<>(
message
,
HttpStatus
.
OK
);
}
@RequestMapping
(
value
=
"generatePdfReport/{id}/{fromDate}/{toDate}"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
TEXT_PLAIN_VALUE
)
public
ResponseEntity
<
String
>
generatePdfReport
(
@PathVariable
(
"id"
)
long
id
,
...
...
@@ -73,6 +56,17 @@ public class AttendanceController {
return
new
ResponseEntity
<>(
result
,
HttpStatus
.
OK
);
}
@RequestMapping
(
value
=
"generatePdfReport/{id}/{fromDate}/{toDate}/{fromTime}/{toTime}"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
TEXT_PLAIN_VALUE
)
public
ResponseEntity
<
String
>
generatePdfReport
(
@PathVariable
(
"id"
)
long
id
,
@PathVariable
(
"fromDate"
)
String
fromDate
,
@PathVariable
(
"toDate"
)
String
toDate
,
@PathVariable
(
"fromTime"
)
String
fromTime
,
@PathVariable
(
"toTime"
)
String
toTime
)
throws
MyTimeException
,
ParseException
{
String
result
=
userService
.
generatePdfReport
(
id
,
fromDate
,
toDate
,
fromTime
,
toTime
);
return
new
ResponseEntity
<>(
result
,
HttpStatus
.
OK
);
}
@RequestMapping
(
value
=
"attendanciesReport/{reportDate}"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
...
...
src/main/java/com/nisum/mytime/service/AttendanceServiceImpl.java
View file @
324a252b
...
...
@@ -75,15 +75,12 @@ public class AttendanceServiceImpl implements AttendanceService {
int
hoursFrom
=
Integer
.
parseInt
(
timeFrom
.
substring
(
0
,
2
));
int
hoursTo
=
Integer
.
parseInt
(
timeTo
.
substring
(
0
,
2
));
if
(
hoursTo
<=
hoursFrom
&&
timeSignFrom
.
equals
(
timeSignTo
)
||
hoursTo
<=
hoursFrom
)
{
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy/MM/d"
);
LocalDate
newtoDate
=
(
LocalDate
.
parse
(
fromDate
,
formatter
)).
plusDays
(
1
);
nextDate
=
newtoDate
.
toString
();
nextDate
=
nextDate
.
replace
(
"-"
,
"/"
);
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-d"
);
LocalDate
newtoDate
=
(
LocalDate
.
parse
(
fromDate
,
formatter
)).
plusDays
(
1
);
nextDate
=
newtoDate
.
toString
();
}
return
employeeDataBaseService
.
fetchEmployeeLoginsBasedOnDatesTime
(
id
,
fromDate
,
nextDate
,
toDate
,
timeFrom
,
timeTo
);
}
@Override
public
String
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
{
...
...
src/main/java/com/nisum/mytime/service/EmployeeDataService.java
View file @
324a252b
...
...
@@ -86,67 +86,66 @@ public class EmployeeDataService {
return
listOfEmpLoginData
;
}
public
List
<
EmpLoginData
>
fetchEmployeeLoginsBasedOnDatesTime
(
long
employeeId
,
String
fromDate
,
String
nextDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
{
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy/MM/dd"
);
LocalDate
formatedFromDate
=
LocalDate
.
parse
(
fromDate
,
formatter
);
LocalDate
formatedNextDate
=
LocalDate
.
parse
(
nextDate
,
formatter
);
LocalDate
formatedToDate
=
LocalDate
.
parse
(
toDate
,
formatter
);
int
differentBetweenDays
=
Period
.
between
(
formatedFromDate
,
formatedToDate
).
getDays
();
long
start_ms
=
System
.
currentTimeMillis
();
String
querys
=
null
;
List
<
EmpLoginData
>
listOfEmpLoginData
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
differentBetweenDays
;
i
++)
{
String
date1
=
fromDate
+
" "
+
fromTime
;
String
date2
=
nextDate
+
" "
+
toTime
;
if
(
i
>
0
)
{
fromDate
=
formatedFromDate
.
plusDays
(
1
).
toString
();
formatedFromDate
=
LocalDate
.
parse
(
fromDate
);
nextDate
=
formatedNextDate
.
plusDays
(
1
).
toString
();
formatedNextDate
=
LocalDate
.
parse
(
nextDate
);
date1
=
fromDate
+
" "
+
fromTime
;
date2
=
nextDate
+
" "
+
toTime
;
}
querys
=
MyTimeUtils
.
LOGIN_REPORT_BY_TIME
+
"'"
+
date1
+
"'"
+
MyTimeUtils
.
LOGIN_REPORT_BY_TIME2
+
"'"
+
date2
+
"'"
+
MyTimeUtils
.
LOGIN_REPORT_BY_TIME3
+
employeeId
+
MyTimeUtils
.
LOGIN_REPORT_BY_TIME4
;
int
countHours
=
0
;
try
(
Connection
connection
=
dbConnection
.
getDBConnection
();
Statement
statement
=
connection
.
createStatement
();
ResultSet
resultSet
=
statement
.
executeQuery
(
querys
.
toString
()))
{
while
(
resultSet
.
next
())
{
EmpLoginData
empLoginData
=
new
EmpLoginData
();
empLoginData
.
setEmployeeId
(
resultSet
.
getString
(
"EmployeeCode"
));
empLoginData
.
setEmployeeName
(
resultSet
.
getString
(
"FirstName"
));
empLoginData
.
setDateOfLogin
(
resultSet
.
getDate
(
"FirstLogin"
).
toString
());
empLoginData
.
setFirstLogin
(
resultSet
.
getTime
(
"FirstLogin"
).
toString
());
empLoginData
.
setLastLogout
(
resultSet
.
getTime
(
"LastLogin"
).
toString
());
public
List
<
EmpLoginData
>
fetchEmployeeLoginsBasedOnDatesTime
(
long
employeeId
,
String
fromDate
,
String
nextDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
{
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
);
LocalDate
formatedFromDate
=
LocalDate
.
parse
(
fromDate
,
formatter
);
LocalDate
formatedNextDate
=
LocalDate
.
parse
(
nextDate
,
formatter
);
LocalDate
formatedToDate
=
LocalDate
.
parse
(
toDate
,
formatter
);
int
differentBetweenDays
=
Period
.
between
(
formatedFromDate
,
formatedToDate
).
getDays
();
long
start_ms
=
System
.
currentTimeMillis
();
String
querys
=
null
;
List
<
EmpLoginData
>
listOfEmpLoginData
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<=
differentBetweenDays
;
i
++)
{
String
date1
=
fromDate
+
" "
+
fromTime
;
String
date2
=
nextDate
+
" "
+
toTime
;
if
(
i
>
0
)
{
fromDate
=
formatedFromDate
.
plusDays
(
1
).
toString
();
formatedFromDate
=
LocalDate
.
parse
(
fromDate
);
nextDate
=
formatedNextDate
.
plusDays
(
1
).
toString
();
formatedNextDate
=
LocalDate
.
parse
(
nextDate
);
date1
=
fromDate
+
" "
+
fromTime
;
date2
=
nextDate
+
" "
+
toTime
;
}
querys
=
MyTimeUtils
.
LOGIN_REPORT_BY_TIME
+
"'"
+
date1
+
"'"
+
MyTimeUtils
.
LOGIN_REPORT_BY_TIME2
+
"'"
+
date2
+
"'"
+
MyTimeUtils
.
LOGIN_REPORT_BY_TIME3
+
employeeId
+
MyTimeUtils
.
LOGIN_REPORT_BY_TIME4
;
LocalDateTime
loginTime
=
resultSet
.
getTimestamp
(
"FirstLogin"
).
toLocalDateTime
();
LocalDateTime
logoutTime
=
resultSet
.
getTimestamp
(
"LastLogin"
).
toLocalDateTime
();
long
totalseconds
=
java
.
time
.
Duration
.
between
(
loginTime
,
logoutTime
).
getSeconds
();
int
hours
=
(
int
)
(
totalseconds
/
3600
);
int
minutes
=
(
int
)
((
totalseconds
%
3600
)
/
60
);
int
seconds
=
(
int
)
((
totalseconds
%
3600
)
%
60
);
empLoginData
.
setTotalLoginTime
(
hours
+
":"
+
minutes
+
":"
+
seconds
);
Date
d
=
MyTimeUtils
.
tdf
.
parse
(
empLoginData
.
getTotalLoginTime
());
countHours
+=
d
.
getTime
();
int
countHours
=
0
;
try
(
Connection
connection
=
dbConnection
.
getDBConnection
();
Statement
statement
=
connection
.
createStatement
();
ResultSet
resultSet
=
statement
.
executeQuery
(
querys
.
toString
()))
{
while
(
resultSet
.
next
())
{
EmpLoginData
empLoginData
=
new
EmpLoginData
();
empLoginData
.
setEmployeeId
(
resultSet
.
getString
(
"EmployeeCode"
));
empLoginData
.
setEmployeeName
(
resultSet
.
getString
(
"FirstName"
));
empLoginData
.
setDateOfLogin
(
resultSet
.
getDate
(
"FirstLogin"
).
toString
());
empLoginData
.
setFirstLogin
(
resultSet
.
getTime
(
"FirstLogin"
).
toString
());
empLoginData
.
setLastLogout
(
resultSet
.
getTime
(
"LastLogin"
).
toString
());
LocalDateTime
loginTime
=
resultSet
.
getTimestamp
(
"FirstLogin"
).
toLocalDateTime
();
LocalDateTime
logoutTime
=
resultSet
.
getTimestamp
(
"LastLogin"
).
toLocalDateTime
();
long
totalseconds
=
java
.
time
.
Duration
.
between
(
loginTime
,
logoutTime
).
getSeconds
();
int
hours
=
(
int
)
(
totalseconds
/
3600
);
int
minutes
=
(
int
)
((
totalseconds
%
3600
)
/
60
);
int
seconds
=
(
int
)
((
totalseconds
%
3600
)
%
60
);
empLoginData
.
setTotalLoginTime
(
hours
+
":"
+
minutes
+
":"
+
seconds
);
Date
d
=
MyTimeUtils
.
tdf
.
parse
(
empLoginData
.
getTotalLoginTime
());
countHours
+=
d
.
getTime
();
listOfEmpLoginData
.
add
(
empLoginData
);
}
if
(!
listOfEmpLoginData
.
isEmpty
())
{
listOfEmpLoginData
.
get
(
0
).
setTotalAvgTime
(
MyTimeUtils
.
tdf
.
format
(
countHours
/
listOfEmpLoginData
.
size
()));
listOfEmpLoginData
.
add
(
empLoginData
);
}
if
(!
listOfEmpLoginData
.
isEmpty
())
{
listOfEmpLoginData
.
get
(
0
).
setTotalAvgTime
(
MyTimeUtils
.
tdf
.
format
(
countHours
/
listOfEmpLoginData
.
size
()));
}
MyTimeLogger
.
getInstance
().
info
(
" Time Taken fecth Employee data based on Dates ::: "
+
(
System
.
currentTimeMillis
()
-
start_ms
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
MyTimeLogger
.
getInstance
().
error
(
e
.
getMessage
());
throw
new
MyTimeException
(
e
.
getMessage
());
}
MyTimeLogger
.
getInstance
().
info
(
" Time Taken fecth Employee data based on Dates ::: "
+
(
System
.
currentTimeMillis
()
-
start_ms
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
MyTimeLogger
.
getInstance
().
error
(
e
.
getMessage
());
throw
new
MyTimeException
(
e
.
getMessage
());
}
return
listOfEmpLoginData
;
}
}
return
listOfEmpLoginData
;
}
}
\ No newline at end of file
src/main/java/com/nisum/mytime/service/UserService.java
View file @
324a252b
package
com
.
nisum
.
mytime
.
service
;
import
java.text.ParseException
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -35,6 +36,9 @@ public interface UserService {
String
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
)
throws
MyTimeException
;
String
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
,
ParseException
;
EmployeeRoles
getEmployeesRole
(
String
emailId
);
void
deleteEmployee
(
String
empId
);
...
...
src/main/java/com/nisum/mytime/service/UserServiceImpl.java
View file @
324a252b
package
com
.
nisum
.
mytime
.
service
;
import
java.text.ParseException
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Comparator
;
...
...
@@ -132,7 +133,13 @@ public class UserServiceImpl implements UserService {
throws
MyTimeException
{
return
pdfReportGenerator
.
generateEmployeeReport
(
id
,
fromDate
,
toDate
);
}
@Override
public
String
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
,
ParseException
{
return
pdfReportGenerator
.
generateEmployeeReport
(
id
,
fromDate
,
toDate
,
fromTime
,
toTime
);
}
@Override
public
List
<
EmployeeRoles
>
getEmployeeRoles
()
throws
MyTimeException
{
//return employeeRolesRepo.findAll();
...
...
src/main/java/com/nisum/mytime/utils/PdfReportGenerator.java
View file @
324a252b
...
...
@@ -2,6 +2,7 @@ package com.nisum.mytime.utils;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.text.ParseException
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -23,6 +24,7 @@ import com.itextpdf.text.pdf.PdfPTable;
import
com.itextpdf.text.pdf.PdfWriter
;
import
com.nisum.mytime.exception.handler.MyTimeException
;
import
com.nisum.mytime.model.EmpLoginData
;
import
com.nisum.mytime.service.AttendanceService
;
import
com.nisum.mytime.service.EmployeeDataService
;
@Component
...
...
@@ -31,8 +33,11 @@ public class PdfReportGenerator {
@Autowired
ResourceLoader
resourceLoader
;
@Autowired
@Autowired
private
EmployeeDataService
employeeDataBaseService
;
@Autowired
private
AttendanceService
attendanceService
;
public
String
generateEmployeeReport
(
long
employeeId
,
String
startDate
,
String
endDate
)
throws
MyTimeException
{
String
fileName
=
employeeId
+
"_"
+
startDate
+
"_"
+
endDate
+
".pdf"
;
...
...
@@ -44,11 +49,26 @@ public class PdfReportGenerator {
}
}
public
String
generateEmployeeReport
(
long
employeeId
,
String
startDate
,
String
endDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
,
ParseException
{
String
fileName
=
employeeId
+
"_"
+
startDate
+
"_"
+
endDate
+
".pdf"
;
List
<
EmpLoginData
>
empLoginDetails
=
getEmployeeData
(
employeeId
,
startDate
,
endDate
,
fromTime
,
toTime
);
if
(
empLoginDetails
.
isEmpty
())
{
return
"No data available"
;
}
else
{
return
createPDF
(
fileName
,
empLoginDetails
,
employeeId
);
}
}
private
List
<
EmpLoginData
>
getEmployeeData
(
long
employeeId
,
String
fromDate
,
String
toDate
)
throws
MyTimeException
{
return
employeeDataBaseService
.
fetchEmployeeLoginsBasedOnDates
(
employeeId
,
fromDate
,
toDate
);
}
private
List
<
EmpLoginData
>
getEmployeeData
(
long
employeeId
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
,
ParseException
{
return
attendanceService
.
employeeLoginReportBasedOnDateTime
(
employeeId
,
fromDate
,
toDate
,
fromTime
,
toTime
);
}
private
String
createPDF
(
String
pdfFilename
,
List
<
EmpLoginData
>
empLoginDatas
,
long
employeeId
)
throws
MyTimeException
{
Document
doc
=
null
;
...
...
src/main/webapp/WEB-INF/controllers/ReportsController.js
View file @
324a252b
...
...
@@ -200,9 +200,9 @@ myApp.controller("reportsController", function($scope, $http, myFactory, $mdDial
empId
=
data
.
empId
;
}
var
defaultURL
=
appConfig
.
appUri
+
"attendance/generatePdfReport/"
+
empId
+
"/"
+
data
.
fromDate
+
"/"
+
data
.
toDate
;
var
overrideURL
=
appConfig
.
appUri
+
"attendance/
employeeLoginReportBasedOnDateTime?empId="
+
empId
+
"&fromDate="
+
data
.
fromDate
+
"&toDate="
+
data
.
toDate
+
"&fromTime="
+
data
.
fromTime
+
"&toTime=
"
+
data
.
toTime
;
var
overrideURL
=
appConfig
.
appUri
+
"attendance/
generatePdfReport/"
+
empId
+
"/"
+
data
.
fromDate
+
"/"
+
data
.
toDate
+
"/"
+
data
.
fromTime
+
"/
"
+
data
.
toTime
;
var
url
=
data
.
isOverride
?
overrideURL
:
defaultURL
;
$http
({
$http
({
method
:
"GET"
,
url
:
url
}).
then
(
function
mySuccess
(
response
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment