161 lines
7.1 KiB
JavaScript
161 lines
7.1 KiB
JavaScript
/**
|
|
* Created by Pensare Software.
|
|
* User: Theo Weijmer
|
|
* Date: 01/03/2018
|
|
* Time: 11:06
|
|
*/
|
|
|
|
dbo.employeehoursreportInit = function () {
|
|
|
|
if ( dbo.employeeHoursreportModel !== undefined ) {
|
|
dbo.employeeHoursreportModel.initModule();
|
|
} else {
|
|
|
|
dbo.employeeHoursreportModel = {
|
|
|
|
months : ko.observableArray( [
|
|
{monthID: 1, monthName: 'jan'},
|
|
{monthID: 2, monthName: 'febr'},
|
|
{monthID: 3, monthName: 'mrt'},
|
|
{monthID: 4, monthName: 'apr'},
|
|
{monthID: 5, monthName: 'mei'},
|
|
{monthID: 6, monthName: 'juni'},
|
|
{monthID: 7, monthName: 'juli'},
|
|
{monthID: 8, monthName: 'aug'},
|
|
{monthID: 9, monthName: 'sept'},
|
|
{monthID: 10, monthName: 'okt'},
|
|
{monthID: 11, monthName: 'nov'},
|
|
{monthID: 12, monthName: 'dec'}
|
|
] ),
|
|
month : ko.observable(),
|
|
selectedMonthID : ko.observable(),
|
|
years : ko.observableArray( [] ),
|
|
selectedYear : ko.observable(),
|
|
employees : ko.observableArray( [] ),
|
|
profitablehoursTotaal : ko.observable(),
|
|
nonprofitablehoursTotaal : ko.observable(),
|
|
nonprojecthoursTotaal : ko.observable(),
|
|
totalhoursTotaal : ko.observable(),
|
|
targetTotaal : ko.observable(),
|
|
occupancyRateTotalTotaal : ko.observable(),
|
|
occupancyRateHoursTotaal : ko.observable(),
|
|
occupancyRateInvoiceTotaal: ko.observable(),
|
|
revenuesTotaal : ko.observable(),
|
|
averageDayRateTotaal : ko.observable(),
|
|
initialize : null,
|
|
|
|
init: function () {
|
|
var vm = dbo.employeeHoursreportModel;
|
|
|
|
vm.initialize = true;
|
|
dbo.reportsDataService.getUsedYears( function ( data ) {
|
|
vm.years.removeAll();
|
|
_.each( data, function ( p ) {
|
|
vm.years.push( {id: p.year, year: p.year} );
|
|
} );
|
|
|
|
vm.selectedYear( (new Date()).getFullYear() );
|
|
vm.selectedMonthID( 1 );
|
|
|
|
vm.initialize = false;
|
|
|
|
vm.initModule();
|
|
} );
|
|
},
|
|
|
|
initModule: function () {
|
|
var vm = dbo.employeeHoursreportModel;
|
|
|
|
vm.refreshTab();
|
|
},
|
|
|
|
setActivetab: function ( tab ) {
|
|
var vm = dbo.employeeHoursreportModel;
|
|
|
|
vm.selectedMonthID( tab );
|
|
|
|
vm.refreshTab();
|
|
},
|
|
|
|
refreshTab: function () {
|
|
var vm = dbo.employeeHoursreportModel;
|
|
|
|
if ( vm.initialize ) return;
|
|
|
|
vm.profitablehoursTotaal( 0 );
|
|
vm.nonprofitablehoursTotaal( 0 );
|
|
vm.nonprojecthoursTotaal( 0 );
|
|
vm.totalhoursTotaal( 0 );
|
|
vm.targetTotaal( 0 );
|
|
vm.occupancyRateTotalTotaal( 0 );
|
|
vm.occupancyRateHoursTotaal( 0 );
|
|
vm.occupancyRateInvoiceTotaal( 0 );
|
|
vm.revenuesTotaal( 0 );
|
|
vm.averageDayRateTotaal( 0 );
|
|
|
|
dbo.employeehoursDataService.getMonthlyEmployeehours( vm.selectedMonthID(), vm.selectedYear(), function ( data ) {
|
|
vm.employees.removeAll();
|
|
var chartData = {};
|
|
chartData.revenues = [];
|
|
chartData.hours = [];
|
|
chartData.averageRate = [];
|
|
chartData.labels = [];
|
|
_.each( data, function ( p ) {
|
|
vm.employees.push( new vm.Employee( p ) );
|
|
|
|
vm.profitablehoursTotaal( vm.profitablehoursTotaal() + Number( p.profitablehours ) );
|
|
vm.nonprofitablehoursTotaal( vm.nonprofitablehoursTotaal() + Number( p.nonprofitablehours ) );
|
|
vm.nonprojecthoursTotaal( vm.nonprojecthoursTotaal() + Number( p.nonprojecthours ) );
|
|
vm.totalhoursTotaal( vm.totalhoursTotaal() + Number( p.totalhours ) );
|
|
vm.targetTotaal( Math.round( vm.targetTotaal() + Number( p.targethours / 12 ) ) );
|
|
vm.revenuesTotaal( Number( vm.revenuesTotaal() ) + Number( p.revenues ) );
|
|
|
|
chartData.labels.push( p.fullname );
|
|
chartData.revenues.push( p.revenues );
|
|
chartData.averageRate.push( Math.round( (p.revenues / p.profitablehours) * 8 ) )
|
|
chartData.hours.push( p.totalhours );
|
|
} );
|
|
vm.occupancyRateTotalTotaal( Math.round( (vm.totalhoursTotaal() / vm.targetTotaal()) * 100 ) );
|
|
vm.occupancyRateHoursTotaal( Math.round( (vm.profitablehoursTotaal() / vm.totalhoursTotaal() ) * 100 ) );
|
|
vm.occupancyRateInvoiceTotaal( Math.round( (vm.profitablehoursTotaal() / vm.targetTotaal()) * 100 ) );
|
|
vm.averageDayRateTotaal( Math.round( Number( vm.revenuesTotaal() ) / Number( vm.profitablehoursTotaal() ) ) * 8 );
|
|
vm.revenuesTotaal( dbo.helpers.thousandSeparator( vm.revenuesTotaal() ) );
|
|
|
|
dbo.charts.drawPie( 'revenues-per-month', chartData.revenues, chartData.labels, 'omzet per medewerker' );
|
|
dbo.charts.drawPie( 'hours-per-month', chartData.hours, chartData.labels, 'uren per medewerker' );
|
|
dbo.charts.drawHoursChart( 'average-rate', chartData.averageRate, chartData.labels, 'gemiddeld tarief', '#78be4b' );
|
|
} );
|
|
},
|
|
|
|
UniqueEmployee: function ( data ) {
|
|
var vm = dbo.employeeHoursreportModel;
|
|
var self = this;
|
|
|
|
self.id = data.id;
|
|
self.fullname = data.fullname;
|
|
self.slug = data.slug;
|
|
},
|
|
|
|
Employee: function ( data ) {
|
|
this.fullname = data.fullname;
|
|
this.profitablehours = data.profitablehours;
|
|
this.nonprofitablehours = data.nonprofitablehours;
|
|
this.nonprojecthours = data.nonprojecthours;
|
|
this.totalhours = data.totalhours;
|
|
this.target = Math.round( data.targethours / 12 );
|
|
this.occupancyRateTotal = Math.round( (data.totalhours / (data.targethours / 12)) * 100 );
|
|
this.occupancyRateHours = Math.round( (data.profitablehours / data.totalhours ) * 100 );
|
|
this.occupancyRateInvoice = Math.round( (data.profitablehours / (data.targethours / 12)) * 100 );
|
|
this.revenues = dbo.helpers.thousandSeparator( data.revenues );
|
|
this.averageDayRate = Math.round( (data.revenues / data.profitablehours) * 8 );
|
|
}
|
|
|
|
}
|
|
|
|
dbo.employeeHoursreportModel.init();
|
|
|
|
ko.applyBindings( dbo.employeeHoursreportModel, document.getElementById( "EMPLOYEEHOURSREPORT" ) );
|
|
|
|
|
|
}
|
|
} |