Files
dbois/public/js/lib/modules/reports/employeeHours.js
T
2018-07-29 10:11:02 +02:00

171 lines
7.7 KiB
JavaScript

/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 01/03/2018
* Time: 11:06
*/
dbo.employeehoursreportInit = function () {
var timeout;
if ( dbo.employeeHoursreportModel !== undefined ) {
dbo.employeeHoursreportModel.initModule();
} else {
dbo.employeeHoursreportModel = {
months : ko.observableArray( [
{monthID: 0, monthName: 'totaal'},
{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,
validYear : ko.observable(),
init: function () {
var vm = dbo.employeeHoursreportModel;
vm.initialize = true;
vm.selectedYear( (new Date()).getFullYear() );
vm.selectedMonthID( 0 );
vm.validYear( true );
vm.initialize = false;
vm.initModule();
},
initModule: function () {
var vm = dbo.employeeHoursreportModel;
vm.refreshTab();
},
checkYear: function () {
var vm = dbo.employeeHoursreportModel;
if ( !Number.isInteger( Number( vm.selectedYear() ) ) ) return vm.validYear( false );
if ( Number( vm.selectedYear() ) > 2100 ) return vm.validYear( false );
if ( Number( vm.selectedYear() ) < 2000 ) return vm.validYear( false );
vm.validYear( true );
vm.initModule();
},
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( Math.round( vm.profitablehoursTotaal() + Number( p.profitablehours ) ) );
vm.nonprofitablehoursTotaal( Math.round( vm.nonprofitablehoursTotaal() + Number( p.nonprofitablehours ) ) );
vm.nonprojecthoursTotaal( Math.round( vm.nonprojecthoursTotaal() + Number( p.nonprojecthours ) ) );
vm.totalhoursTotaal( Math.round( vm.totalhoursTotaal() + Number( p.totalhours ) ) );
vm.targetTotaal( Math.round( vm.targetTotaal() + Number( p.targethours ) ) );
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()) * 1000 ) / 10 );
vm.occupancyRateHoursTotaal( Math.round( (vm.profitablehoursTotaal() / vm.totalhoursTotaal()) * 1000 ) / 10 );
vm.occupancyRateInvoiceTotaal( Math.round( (vm.profitablehoursTotaal() / vm.targetTotaal()) * 1000 ) / 10 );
console.log( Number( vm.revenuesTotaal() ) );
console.log( Number( vm.profitablehoursTotaal() ) );
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 = Math.round( data.totalhours );
this.target = dbo.helpers.numberWithPoints( Math.round( data.targethours ) );
this.occupancyRateTotal = Math.round( (data.totalhours / data.targethours) * 1000 ) / 10;
this.occupancyRateHours = Math.round( (data.profitablehours / data.totalhours) * 1000 ) / 10;
this.occupancyRateInvoice = Math.round( (data.profitablehours / data.targethours) * 1000 ) / 10;
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" ) );
}
}