File: /home/imensosw/public_html/imenso.co/timesheet/js/report.js
// THIS FILE REQURES THAT THE LIB FILE IS LOADED FIRST
if (!_.isObject(app)) {
alert("System Library failed to load [SYSLD01]. Pleasr report this error to support@nthriveeducation.com");
//the app object is defined in lib.js
}
if(app.dev){
app.log("DEV MODE ON");
}
app.files = [{
name:"reporttable",
file:'./../../inc/report/table.inc.html'
},
{
name:'reportrow',
file:'./../../inc/report/row.inc.html'
},
{
name:'reportsearch',
file:'./../../inc/report/search.inc.html'
},
{
name:'select',
file:'./../../inc/common/select.inc.html'
},
{
name:'xlsrow',
file:'./../../inc/report/xlsrow.inc.html'
},
{
name:'xlstable',
file:'./../../inc/report/xlstable.inc.html'
},
{
name:'pagination',
file:'./../../inc/common/pagination.inc.html'
},
{
name:'navbar',
file:'./../../inc/layouts/navbar.inc.html'
}
];
app.filter={
project_id:"",
user_id:"",
task_id:"",
from_date:"",
to_date:"",
page:1,
sorting:"firstname",
sortingby:"asc",
download:""
};
$(document).ready(function(){
app.setListeners();
app.init(function(){
app.startApp();
});
});
app.setListeners = function() {
app.setLibListeners();
$(document).on('click', '#searchreportbutton', function(e) {
app.filter.project_id=$('#project_id').val();
app.filter.user_id=$('#user_id').val();
app.filter.task_id=$('#task_id').val();
app.filter.from_date=$('#from_date').val();
app.filter.to_date=$('#to_date').val();
app.filter.download="";
app.getReport();
});
$(document).on('click touch', '.paginationlink a', function(e) {
app.filter.download="";
app.filter.page=$(this).attr("data-page");
app.getReport();
$('.paginationlink').removeClass('active');
$(this).closest('.paginationlink').addClass('active');
});
$(document).on('click touch', '.download_xls', function(e){
app.filter.download="yes";
app.getReport();
});
}
app.launchUser = function() {
app.log("Launching with user ",app.user);
$.ajax({
method: "POST",
url: app.location+"api/imensoapi.php",
dataType: "json",
data: {
action: "launchload",
user: app.user
}
})
.fail(function() {
alert("There was an error connecting to the server SR[01]")
})
.done(function(resp) {
if (resp.resp == 'OK') {
if (resp.error) {
alert("Transaction error. " + resp.error);
} else {
app.log("User launched");
app.user = Cookies.getJSON('usertoken');
app.launcheScreen();
}
} else {
alert("There was an error connecting to the server SR[02]")
}
}); //- ajax
} //- launchUser
app.launcheScreen=function(){
$("body").prepend(app.templates.navbar({
active:"report",
type:app.user.acces_level
}));
app.getReportSelect();
}
app.startApp = function(){
app.log("Starting");
app.user = Cookies.getJSON('usertoken');
if (app.user && app.user.token && app.user.token.length > 20) {
app.launchUser();
} else {
window.location.href=app.location;
}
}
app.getReport = function(){
app.reportForm={
project_id:app.filter.project_id,
user_id:app.filter.user_id,
task_id:app.filter.task_id,
from_date:app.filter.from_date,
to_date:app.filter.to_date,
page:app.filter.page,
sorting:app.filter.sorting,
sortingby:app.filter.sortingby,
download:app.filter.download
};
$.ajax({
method: "POST",
url: app.location+"api/admin.php",
dataType: "json",
data:{
action: "getreport",
report: app.reportForm,
token:app.user.token
}
}).fail(function(){
alert("There was an error connecting to the server SR[01]");
}).done(function(resp){
if(resp.resp == "OK")
{
app.resp = resp;
app.showReportList();
}
else{
alert("There was an error connecting to the server SR[02]")
}
});
}
app.getReportSelect = function(){
$.ajax({
method: "POST",
url: app.location+"api/admin.php",
dataType: "json",
data:{
action: "getreportform",
token:app.user.token
}
}).fail(function(){
alert("There was an error connecting to the server SR[01]");
}).done(function(resp){
if(resp.resp == "OK")
{
app.respprojecttask = resp;
app.getReport();
}
else{
alert("There was an error connecting to the server SR[02]")
}
});
}
app.showReportList = function(){
if(app.filter.download!="")
{
var hours=0;
var minute=0;
var downloads = [];
_.each(app.resp.reports, function(downld){
tm=downld.total_time.split(":");
hours+=Number(tm[0]);
minute+=Number(tm[1]);
downloads.push(app.templates.xlsrow(downld));
});
if(minute>59)
{
remaningHours=Math.floor(minute/60);
minute=minute%60;
hours+=Number(remaningHours);
}
$("#resultxls").html(app.templates.xlstable({
downloads: downloads.join("")
}));
$('#total_time').html(hours+":"+minute);
tablesToExcel(['export_table'], ['TimeSheet Details'], 'Timesheet.xls', 'Excel');
return false;
}
var rows = [];
_.each(app.resp.reports, function(report){
rows.push(app.templates.reportrow(report));
});
if($('#reportsearch').length==0)
{
var projects = [];
var tasks = [];
var users=[];
_.each(app.respprojecttask.getproject, function(getp){
projects.push(app.templates.select(getp));
});
_.each(app.respprojecttask.gettask, function(gett){
tasks.push(app.templates.select(gett));
});
_.each(app.respprojecttask.getuser, function(gett){
users.push(app.templates.select(gett));
});
$("#maincontainer").html(app.templates.reportsearch({
projects: projects.join(""),
tasks: tasks.join(""),
users:users.join("")
}));
setTimeout(function(){
$('.chosen-select').chosen('update');
},100);
}
$("#result").html(app.templates.reporttable({
rows: rows.join("")
}));
$('#pagination').html(app.templates.pagination({
pagination: app.resp.paginationresult
}));
}
app.loadTemplates = function() {
app.templates.modal = _.template("<div class='modal fade' tabindex='-1' role='dialog' id='modal'><div class='modal-dialog' role='document'><div class='modal-content'><div class='modal-header'><h5 class='modal-title'><%=title%></h5><button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>×</span></button></div><div class='modal-body'><%=content%></div><div style='display:none' class='modal-footer'><button type='button' class='btn btn-default' data-dismiss='modal'>Close</button></div></div></div></div>");
}
;