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
e38dc67d
Unverified
Commit
e38dc67d
authored
Sep 07, 2018
by
mshaik-nisum-com
Committed by
GitHub
Sep 07, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #189 from nisum-inc/FEATURE/ExportExcelAndPdf
Feature/export excel and pdf
parents
337099ad
1911ff3b
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
182 additions
and
34 deletions
+182
-34
AttendanceController.java
...ava/com/nisum/mytime/controller/AttendanceController.java
+6
-6
AttendanceService.java
...main/java/com/nisum/mytime/service/AttendanceService.java
+1
-1
AttendanceServiceImpl.java
.../java/com/nisum/mytime/service/AttendanceServiceImpl.java
+2
-2
ProjectServiceImpl.java
...ain/java/com/nisum/mytime/service/ProjectServiceImpl.java
+2
-6
UserService.java
src/main/java/com/nisum/mytime/service/UserService.java
+2
-2
UserServiceImpl.java
src/main/java/com/nisum/mytime/service/UserServiceImpl.java
+2
-2
PdfReportGenerator.java
src/main/java/com/nisum/mytime/utils/PdfReportGenerator.java
+31
-8
ReportsController.js
src/main/webapp/WEB-INF/controllers/ReportsController.js
+116
-3
default-styles.css
src/main/webapp/WEB-INF/css/default-styles.css
+4
-1
reports.html
src/main/webapp/WEB-INF/templates/reports.html
+14
-2
AttendanceControllerTest.java
...nisum/mytime/controllertest/AttendanceControllerTest.java
+2
-1
No files found.
src/main/java/com/nisum/mytime/controller/AttendanceController.java
View file @
e38dc67d
...
@@ -48,22 +48,22 @@ public class AttendanceController {
...
@@ -48,22 +48,22 @@ public class AttendanceController {
}
}
@RequestMapping
(
value
=
"generatePdfReport/{id}/{fromDate}/{toDate}"
,
@RequestMapping
(
value
=
"generatePdfReport/{id}/{fromDate}/{toDate}"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
TEXT_PLAI
N_VALUE
)
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSO
N_VALUE
)
public
ResponseEntity
<
String
>
generatePdfReport
(
@PathVariable
(
"id"
)
long
id
,
public
ResponseEntity
<
List
>
generatePdfReport
(
@PathVariable
(
"id"
)
long
id
,
@PathVariable
(
"fromDate"
)
String
fromDate
,
@PathVariable
(
"fromDate"
)
String
fromDate
,
@PathVariable
(
"toDate"
)
String
toDate
)
throws
MyTimeException
{
@PathVariable
(
"toDate"
)
String
toDate
)
throws
MyTimeException
{
String
result
=
userService
.
generatePdfReport
(
id
,
fromDate
,
toDate
);
List
result
=
userService
.
generatePdfReport
(
id
,
fromDate
,
toDate
);
return
new
ResponseEntity
<>(
result
,
HttpStatus
.
OK
);
return
new
ResponseEntity
<>(
result
,
HttpStatus
.
OK
);
}
}
@RequestMapping
(
value
=
"generatePdfReport/{id}/{fromDate}/{toDate}/{fromTime}/{toTime}"
,
@RequestMapping
(
value
=
"generatePdfReport/{id}/{fromDate}/{toDate}/{fromTime}/{toTime}"
,
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
TEXT_PLAI
N_VALUE
)
method
=
RequestMethod
.
GET
,
produces
=
MediaType
.
APPLICATION_JSO
N_VALUE
)
public
ResponseEntity
<
String
>
generatePdfReport
(
@PathVariable
(
"id"
)
long
id
,
public
ResponseEntity
<
List
>
generatePdfReport
(
@PathVariable
(
"id"
)
long
id
,
@PathVariable
(
"fromDate"
)
String
fromDate
,
@PathVariable
(
"fromDate"
)
String
fromDate
,
@PathVariable
(
"toDate"
)
String
toDate
,
@PathVariable
(
"toDate"
)
String
toDate
,
@PathVariable
(
"fromTime"
)
String
fromTime
,
@PathVariable
(
"fromTime"
)
String
fromTime
,
@PathVariable
(
"toTime"
)
String
toTime
)
throws
MyTimeException
,
ParseException
{
@PathVariable
(
"toTime"
)
String
toTime
)
throws
MyTimeException
,
ParseException
{
String
result
=
userService
.
generatePdfReport
(
id
,
fromDate
,
toDate
,
fromTime
,
toTime
);
List
result
=
userService
.
generatePdfReport
(
id
,
fromDate
,
toDate
,
fromTime
,
toTime
);
return
new
ResponseEntity
<>(
result
,
HttpStatus
.
OK
);
return
new
ResponseEntity
<>(
result
,
HttpStatus
.
OK
);
}
}
...
...
src/main/java/com/nisum/mytime/service/AttendanceService.java
View file @
e38dc67d
...
@@ -12,7 +12,7 @@ public interface AttendanceService {
...
@@ -12,7 +12,7 @@ public interface AttendanceService {
List
<
AttendenceData
>
getAttendanciesReport
(
String
reportDate
,
String
shift
)
throws
MyTimeException
,
SQLException
;
List
<
AttendenceData
>
getAttendanciesReport
(
String
reportDate
,
String
shift
)
throws
MyTimeException
,
SQLException
;
String
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
;
List
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
;
List
<
EmpLoginData
>
employeeLoginReportBasedOnDateTime
(
long
id
,
String
fromDate
,
List
<
EmpLoginData
>
employeeLoginReportBasedOnDateTime
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
,
ParseException
;
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
,
ParseException
;
...
...
src/main/java/com/nisum/mytime/service/AttendanceServiceImpl.java
View file @
e38dc67d
...
@@ -61,8 +61,8 @@ public class AttendanceServiceImpl implements AttendanceService {
...
@@ -61,8 +61,8 @@ public class AttendanceServiceImpl implements AttendanceService {
}
}
@Override
@Override
public
String
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
public
List
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
{
throws
MyTimeException
{
return
pdfReportGenerator
.
generateEmployeeReport
(
id
,
fromDate
,
toDate
);
return
pdfReportGenerator
.
generateEmployeeReport
(
id
,
fromDate
,
toDate
);
}
}
...
...
src/main/java/com/nisum/mytime/service/ProjectServiceImpl.java
View file @
e38dc67d
...
@@ -100,7 +100,7 @@ public class ProjectServiceImpl implements ProjectService {
...
@@ -100,7 +100,7 @@ public class ProjectServiceImpl implements ProjectService {
@Override
@Override
public
String
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
)
throws
MyTimeException
{
public
String
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
)
throws
MyTimeException
{
return
pdfReportGenerator
.
generate
Employe
eReport
(
id
,
fromDate
,
toDate
);
return
pdfReportGenerator
.
generateeReport
(
id
,
fromDate
,
toDate
);
}
}
@Override
@Override
...
@@ -771,8 +771,7 @@ public class ProjectServiceImpl implements ProjectService {
...
@@ -771,8 +771,7 @@ public class ProjectServiceImpl implements ProjectService {
billingsSorted
=
(
billings
==
null
||
billings
.
size
()
==
0
)
?
billings
:
billings
.
stream
().
sorted
(
billingsSorted
=
(
billings
==
null
||
billings
.
size
()
==
0
)
?
billings
:
billings
.
stream
().
sorted
(
Comparator
.
comparing
(
BillingDetails:
:
getCreateDate
).
reversed
()).
collect
(
Collectors
.
toList
());
Comparator
.
comparing
(
BillingDetails:
:
getCreateDate
).
reversed
()).
collect
(
Collectors
.
toList
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// TODO: handle exception
}
}
return
billingsSorted
;
return
billingsSorted
;
}
}
...
@@ -784,7 +783,6 @@ public class ProjectServiceImpl implements ProjectService {
...
@@ -784,7 +783,6 @@ public class ProjectServiceImpl implements ProjectService {
billingsSorted
=
(
billings
==
null
||
billings
.
size
()
==
0
)
?
billings
:
billings
.
stream
().
sorted
(
billingsSorted
=
(
billings
==
null
||
billings
.
size
()
==
0
)
?
billings
:
billings
.
stream
().
sorted
(
Comparator
.
comparing
(
BillingDetails:
:
getCreateDate
).
reversed
()).
collect
(
Collectors
.
toList
());
Comparator
.
comparing
(
BillingDetails:
:
getCreateDate
).
reversed
()).
collect
(
Collectors
.
toList
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// TODO: handle exception
}
}
return
billingsSorted
;
return
billingsSorted
;
}
}
...
@@ -801,7 +799,6 @@ public class ProjectServiceImpl implements ProjectService {
...
@@ -801,7 +799,6 @@ public class ProjectServiceImpl implements ProjectService {
billingsSorted
=
(
billings
==
null
||
billings
.
size
()
==
0
)
?
billings
:
billings
.
stream
().
sorted
(
billingsSorted
=
(
billings
==
null
||
billings
.
size
()
==
0
)
?
billings
:
billings
.
stream
().
sorted
(
Comparator
.
comparing
(
BillingDetails:
:
getBillingStartDate
).
reversed
()).
collect
(
Collectors
.
toList
());
Comparator
.
comparing
(
BillingDetails:
:
getBillingStartDate
).
reversed
()).
collect
(
Collectors
.
toList
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// TODO: handle exception
}
}
return
billingsSorted
;
return
billingsSorted
;
}
}
...
@@ -818,7 +815,6 @@ public class ProjectServiceImpl implements ProjectService {
...
@@ -818,7 +815,6 @@ public class ProjectServiceImpl implements ProjectService {
billingsSorted
=
(
billings
==
null
||
billings
.
size
()
==
0
)
?
billings
:
billings
.
stream
().
sorted
(
billingsSorted
=
(
billings
==
null
||
billings
.
size
()
==
0
)
?
billings
:
billings
.
stream
().
sorted
(
Comparator
.
comparing
(
BillingDetails:
:
getBillingStartDate
).
reversed
()).
collect
(
Collectors
.
toList
());
Comparator
.
comparing
(
BillingDetails:
:
getBillingStartDate
).
reversed
()).
collect
(
Collectors
.
toList
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// TODO: handle exception
}
}
return
billingsSorted
;
return
billingsSorted
;
}
}
...
...
src/main/java/com/nisum/mytime/service/UserService.java
View file @
e38dc67d
...
@@ -33,10 +33,10 @@ public interface UserService {
...
@@ -33,10 +33,10 @@ public interface UserService {
EmployeeRoles
assigingEmployeeRole
(
EmployeeRoles
employeeRoles
,
String
empId
)
EmployeeRoles
assigingEmployeeRole
(
EmployeeRoles
employeeRoles
,
String
empId
)
throws
MyTimeException
;
throws
MyTimeException
;
String
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
)
List
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
)
throws
MyTimeException
;
throws
MyTimeException
;
String
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
List
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
,
ParseException
;
throws
MyTimeException
,
ParseException
;
EmployeeRoles
getEmployeesRole
(
String
emailId
);
EmployeeRoles
getEmployeesRole
(
String
emailId
);
...
...
src/main/java/com/nisum/mytime/service/UserServiceImpl.java
View file @
e38dc67d
...
@@ -128,13 +128,13 @@ public class UserServiceImpl implements UserService {
...
@@ -128,13 +128,13 @@ public class UserServiceImpl implements UserService {
}
}
@Override
@Override
public
String
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
)
public
List
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
)
throws
MyTimeException
{
throws
MyTimeException
{
return
pdfReportGenerator
.
generateEmployeeReport
(
id
,
fromDate
,
toDate
);
return
pdfReportGenerator
.
generateEmployeeReport
(
id
,
fromDate
,
toDate
);
}
}
@Override
@Override
public
String
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
public
List
generatePdfReport
(
long
id
,
String
fromDate
,
String
toDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
,
ParseException
{
throws
MyTimeException
,
ParseException
{
return
pdfReportGenerator
.
generateEmployeeReport
(
id
,
fromDate
,
toDate
,
fromTime
,
toTime
);
return
pdfReportGenerator
.
generateEmployeeReport
(
id
,
fromDate
,
toDate
,
fromTime
,
toTime
);
}
}
...
...
src/main/java/com/nisum/mytime/utils/PdfReportGenerator.java
View file @
e38dc67d
...
@@ -3,6 +3,7 @@ package com.nisum.mytime.utils;
...
@@ -3,6 +3,7 @@ package com.nisum.mytime.utils;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
import
java.text.ParseException
;
import
java.text.ParseException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -39,23 +40,45 @@ public class PdfReportGenerator {
...
@@ -39,23 +40,45 @@ public class PdfReportGenerator {
@Autowired
@Autowired
private
AttendanceService
attendanceService
;
private
AttendanceService
attendanceService
;
public
String
generateEmployeeReport
(
long
employeeId
,
String
startDate
,
String
endDate
)
throws
MyTimeException
{
public
List
generateEmployeeReport
(
long
employeeId
,
String
startDate
,
String
endDate
)
throws
MyTimeException
{
String
fileName
=
employeeId
+
"_"
+
startDate
+
"_"
+
endDate
+
".pdf"
;
String
fileName
=
employeeId
+
"_"
+
startDate
+
"_"
+
endDate
+
".pdf"
;
List
<
EmpLoginData
>
empLoginDetails
=
getEmployeeData
(
employeeId
,
startDate
,
endDate
);
List
<
EmpLoginData
>
empLoginDetails
=
getEmployeeData
(
employeeId
,
startDate
,
endDate
);
List
filenameData
=
new
ArrayList
<>();
if
(
empLoginDetails
.
isEmpty
())
{
if
(
empLoginDetails
.
isEmpty
())
{
return
"No data available"
;
String
message
=
"No data available"
;
}
else
{
filenameData
.
add
(
message
);
return
createPDF
(
fileName
,
empLoginDetails
,
employeeId
);
return
filenameData
;
}
}
else
{
String
file
=
createPDF
(
fileName
,
empLoginDetails
,
employeeId
);
filenameData
.
add
(
file
);
filenameData
.
add
(
empLoginDetails
);
return
filenameData
;
}
}
}
public
String
generateEmployeeReport
(
long
employeeId
,
String
startDate
,
String
endDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
,
ParseException
{
public
String
generateeReport
(
long
employeeId
,
String
startDate
,
String
endDate
)
throws
MyTimeException
{
String
fileName
=
employeeId
+
"_"
+
startDate
+
"_"
+
endDate
+
".pdf"
;
List
<
EmpLoginData
>
empLoginDetails
=
getEmployeeData
(
employeeId
,
startDate
,
endDate
);
if
(
empLoginDetails
.
isEmpty
())
{
String
message
=
"No data available"
;
return
message
;
}
else
{
return
fileName
;
}
}
public
List
generateEmployeeReport
(
long
employeeId
,
String
startDate
,
String
endDate
,
String
fromTime
,
String
toTime
)
throws
MyTimeException
,
ParseException
{
String
fileName
=
employeeId
+
"_"
+
startDate
+
"_"
+
endDate
+
".pdf"
;
String
fileName
=
employeeId
+
"_"
+
startDate
+
"_"
+
endDate
+
".pdf"
;
List
<
EmpLoginData
>
empLoginDetails
=
getEmployeeData
(
employeeId
,
startDate
,
endDate
,
fromTime
,
toTime
);
List
<
EmpLoginData
>
empLoginDetails
=
getEmployeeData
(
employeeId
,
startDate
,
endDate
,
fromTime
,
toTime
);
List
filenameData
=
new
ArrayList
<>();
if
(
empLoginDetails
.
isEmpty
())
{
if
(
empLoginDetails
.
isEmpty
())
{
return
"No data available"
;
String
message
=
"No data available"
;
filenameData
.
add
(
message
);
return
filenameData
;
}
else
{
}
else
{
return
createPDF
(
fileName
,
empLoginDetails
,
employeeId
);
String
file
=
createPDF
(
fileName
,
empLoginDetails
,
employeeId
);
filenameData
.
add
(
file
);
filenameData
.
add
(
empLoginDetails
);
return
filenameData
;
}
}
}
}
...
...
src/main/webapp/WEB-INF/controllers/ReportsController.js
View file @
e38dc67d
myApp
.
controller
(
"reportsController"
,
function
(
$scope
,
$http
,
myFactory
,
$mdDialog
,
appConfig
,
$timeout
,
$compile
)
{
myApp
.
directive
(
'excelExport'
,
function
()
{
return
{
restrict
:
'A'
,
scope
:
{
fileName
:
"@"
,
data
:
"&exportData"
},
replace
:
true
,
template
:
'<button class="btn btn-primary btn-ef btn-ef-3 btn-ef-3c mb-10" ng-click="download()">Export to Excel <i class="fa fa-download"></i></button>'
,
link
:
function
(
scope
,
element
)
{
scope
.
download
=
function
()
{
function
datenum
(
v
,
date1904
)
{
if
(
date1904
)
v
+=
1462
;
var
epoch
=
Date
.
parse
(
v
);
return
(
epoch
-
new
Date
(
Date
.
UTC
(
1899
,
11
,
30
)))
/
(
24
*
60
*
60
*
1000
);
};
function
getSheet
(
data
,
opts
)
{
var
ws
=
{};
var
range
=
{
s
:
{
c
:
10000000
,
r
:
10000000
},
e
:
{
c
:
0
,
r
:
0
}};
for
(
var
R
=
0
;
R
!=
data
.
length
;
++
R
)
{
for
(
var
C
=
0
;
C
!=
data
[
R
].
length
;
++
C
)
{
if
(
range
.
s
.
r
>
R
)
range
.
s
.
r
=
R
;
if
(
range
.
s
.
c
>
C
)
range
.
s
.
c
=
C
;
if
(
range
.
e
.
r
<
R
)
range
.
e
.
r
=
R
;
if
(
range
.
e
.
c
<
C
)
range
.
e
.
c
=
C
;
var
cell
=
{
v
:
data
[
R
][
C
]
};
if
(
cell
.
v
==
null
)
continue
;
var
cell_ref
=
XLSX
.
utils
.
encode_cell
({
c
:
C
,
r
:
R
});
if
(
typeof
cell
.
v
===
'number'
)
cell
.
t
=
'n'
;
else
if
(
typeof
cell
.
v
===
'boolean'
)
cell
.
t
=
'b'
;
else
if
(
cell
.
v
instanceof
Date
)
{
cell
.
t
=
'n'
;
cell
.
z
=
XLSX
.
SSF
.
_table
[
14
];
cell
.
v
=
datenum
(
cell
.
v
);
}
else
cell
.
t
=
's'
;
ws
[
cell_ref
]
=
cell
;
}
}
if
(
range
.
s
.
c
<
10000000
)
ws
[
'!ref'
]
=
XLSX
.
utils
.
encode_range
(
range
);
return
ws
;
};
function
Workbook
()
{
if
(
!
(
this
instanceof
Workbook
))
return
new
Workbook
();
this
.
SheetNames
=
[];
this
.
Sheets
=
{};
}
var
wb
=
new
Workbook
(),
ws
=
getSheet
(
scope
.
data
());
/* add worksheet to workbook */
wb
.
SheetNames
.
push
(
scope
.
fileName
);
wb
.
Sheets
[
scope
.
fileName
]
=
ws
;
var
wbout
=
XLSX
.
write
(
wb
,
{
bookType
:
'xlsx'
,
bookSST
:
true
,
type
:
'binary'
});
function
s2ab
(
s
)
{
var
buf
=
new
ArrayBuffer
(
s
.
length
);
var
view
=
new
Uint8Array
(
buf
);
for
(
var
i
=
0
;
i
!=
s
.
length
;
++
i
)
view
[
i
]
=
s
.
charCodeAt
(
i
)
&
0xFF
;
return
buf
;
}
saveAs
(
new
Blob
([
s2ab
(
wbout
)],{
type
:
"application/octet-stream"
}),
scope
.
fileName
+
'.xlsx'
);
};
}
};
}
)
.
controller
(
"reportsController"
,
function
(
$scope
,
$http
,
myFactory
,
$mdDialog
,
appConfig
,
$timeout
,
$compile
)
{
$scope
.
records
=
[];
$scope
.
records
=
[];
$scope
.
searchId
=
""
;
$scope
.
searchId
=
""
;
// Date picker related code
// Date picker related code
...
@@ -7,6 +83,7 @@ myApp.controller("reportsController", function($scope, $http, myFactory, $mdDial
...
@@ -7,6 +83,7 @@ myApp.controller("reportsController", function($scope, $http, myFactory, $mdDial
$scope
.
fromDate
=
today
;
$scope
.
fromDate
=
today
;
$scope
.
toDate
=
today
;
$scope
.
toDate
=
today
;
$scope
.
reportMsg
=
"Please generate a report for preview."
;
$scope
.
reportMsg
=
"Please generate a report for preview."
;
$scope
.
isDataAvailable
=
false
;
$scope
.
validateDates
=
function
(
dateValue
,
from
)
{
$scope
.
validateDates
=
function
(
dateValue
,
from
)
{
if
(
from
==
"FromDate"
){
if
(
from
==
"FromDate"
){
var
toDat
=
$scope
.
toDate
;
var
toDat
=
$scope
.
toDate
;
...
@@ -225,10 +302,14 @@ myApp.controller("reportsController", function($scope, $http, myFactory, $mdDial
...
@@ -225,10 +302,14 @@ myApp.controller("reportsController", function($scope, $http, myFactory, $mdDial
method
:
"GET"
,
method
:
"GET"
,
url
:
url
url
:
url
}).
then
(
function
mySuccess
(
response
)
{
}).
then
(
function
mySuccess
(
response
)
{
if
(
response
.
data
==
"No data available"
){
if
(
response
.
data
[
0
]
==
"No data available"
){
$scope
.
pdfUrl
=
response
.
data
;
$scope
.
pdfUrl
=
response
.
data
;
$scope
.
isDataAvailable
=
false
;
}
else
{
}
else
{
$scope
.
pdfUrl
=
"reports/"
+
response
.
data
;
$scope
.
pdfUrl
=
"reports/"
+
response
.
data
[
0
];
$scope
.
jsonToExport
=
response
.
data
[
1
];
excelDataFormation
();
$scope
.
isDataAvailable
=
true
;
}
}
},
function
myError
(
response
)
{
},
function
myError
(
response
)
{
showAlert
(
"Something went wrong while generating report!!!"
);
showAlert
(
"Something went wrong while generating report!!!"
);
...
@@ -236,6 +317,38 @@ myApp.controller("reportsController", function($scope, $http, myFactory, $mdDial
...
@@ -236,6 +317,38 @@ myApp.controller("reportsController", function($scope, $http, myFactory, $mdDial
});
});
}
}
// function generateExcelReport(id,data) {
// debugger;
//
// var defaultURL= appConfig.appUri + "attendance/employeeLoginReportBasedOnDateTime?empId=" + id + "&fromDate=" + data.fromDate + "&toDate=" + data.toDate + "&fromTime=" + data.fromTime + "&toTime=" + data.toTime
// $http({
// method : "GET",
// url : defaultURL
// }).then(function mySuccess(response) {
// if(response.data){
// console.log(response.data);
// $scope.jsonToExport = response.data;
// excelDataFormation();
// }
// }, function myError(response) {
// showAlert("Something went wrong while generating report!!!");
// $scope.pdfUrl = "";
// });
// }
function
excelDataFormation
(){
// Prepare Excel data:
$scope
.
fileName
=
"report"
;
$scope
.
exportData
=
[];
// Headers:
$scope
.
exportData
.
push
([
"ID"
,
"Name"
,
"Date"
,
"Login Time"
,
"Logout Time"
,
"Total Hours"
]);
// Data:
angular
.
forEach
(
$scope
.
jsonToExport
,
function
(
value
,
key
)
{
$scope
.
exportData
.
push
([
value
.
employeeId
,
value
.
employeeName
,
value
.
dateOfLogin
,
value
.
firstLogin
,
value
.
lastLogout
,
value
.
totalLoginTime
]);
});
}
function
getFormattedDate
(
date
){
function
getFormattedDate
(
date
){
var
day
=
date
.
getDate
();
var
day
=
date
.
getDate
();
var
month
=
date
.
getMonth
()
+
1
;
var
month
=
date
.
getMonth
()
+
1
;
...
...
src/main/webapp/WEB-INF/css/default-styles.css
View file @
e38dc67d
...
@@ -235,4 +235,7 @@ md-select {
...
@@ -235,4 +235,7 @@ md-select {
}
}
.my-css-class
{
.my-css-class
{
margin-left
:
20px
;
margin-left
:
20px
;
}
}
\ No newline at end of file
.align-button
{
margin-left
:
-2%
;
}
src/main/webapp/WEB-INF/templates/reports.html
View file @
e38dc67d
...
@@ -81,6 +81,18 @@
...
@@ -81,6 +81,18 @@
</div>
</div>
</div>
</div>
</div>
</div>
<div
class=
"form-horizontal"
>
<div
class=
"form-group"
>
<div
class=
"form-inline col-lg-12 align-button"
>
<div
class=
"form-group col-lg-9"
>
</div>
<div
class=
"form-group col-lg-2"
>
<div
excel-export
export-data=
"exportData"
file-name=
"{{fileName}}"
ng-disabled =
"!isDataAvailable"
></div>
</div>
<div
class=
"form-group col-lg-1"
>
<button
class=
"btn btn-primary btn-ef btn-ef-3 btn-ef-3c mb-10"
ng-click=
"print(pdfUrl)"
ng-disabled =
"!isDataAvailable"
>
Save as PDF
<i
class=
"fa fa-download"
></i></button>
</div>
</div>
</div>
</div>
</div>
</div>
src/test/java/com/nisum/mytime/controllertest/AttendanceControllerTest.java
View file @
e38dc67d
...
@@ -55,7 +55,8 @@ public class AttendanceControllerTest {
...
@@ -55,7 +55,8 @@ public class AttendanceControllerTest {
@Test
@Test
public
void
testgeneratePdfReport
()
throws
Exception
{
public
void
testgeneratePdfReport
()
throws
Exception
{
when
(
userService
.
generatePdfReport
(
12345
,
"2017-11-18"
,
"2017-12-18"
)).
thenReturn
(
"empLoginDetails"
);
List
list
=
new
ArrayList
();
when
(
userService
.
generatePdfReport
(
12345
,
"2017-11-18"
,
"2017-12-18"
)).
thenReturn
(
list
);
mockMvc
.
perform
(
get
(
"/attendance/generatePdfReport/12345/2017-11-18/2017-12-18"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
mockMvc
.
perform
(
get
(
"/attendance/generatePdfReport/12345/2017-11-18/2017-12-18"
)).
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
());
verify
(
userService
).
generatePdfReport
(
12345
,
"2017-11-18"
,
"2017-12-18"
);
verify
(
userService
).
generatePdfReport
(
12345
,
"2017-11-18"
,
"2017-12-18"
);
}
}
...
...
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