Files
dbois/public/js/lib/modules/reports/monthlyEmployeeHoursModule.js
T
2018-04-21 16:51:01 +02:00

399 lines
22 KiB
JavaScript

/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 08/02/2018
* Time: 15:32
*/
dbo.monthlyemployeehoursInit = function () {
var timeout;
if ( dbo.monthlyEmployeeHoursModel !== undefined ) {
dbo.monthlyEmployeeHoursModel.initModule();
} else {
dbo.monthlyEmployeeHoursModel = {
uniqueEmployees : ko.observableArray( [] ),
uniqueYears : ko.observableArray( [] ),
sluggy : ko.observable( 'euro' ),
years : ko.observableArray( [] ),
selectedYear : ko.observable(),
currentTab : false,
recap : ko.observableArray( [] ),
totalPerEmployee : ko.observableArray( [] ),
totalEmployeeRevenues : ko.observable(),
totalAvailableRevenues : ko.observable(),
totalEmployeeHours : ko.observable(),
totalEmployeeAvailableHours: ko.observable(),
totalBudget : ko.observable(),
totalOwnRevenue : ko.observable(),
totalCosts : ko.observable(),
totalAvailableBudget : ko.observable(),
totalSaldo : ko.observable(),
totalWorkInProgress : ko.observable(),
totalInvoicedYear : ko.observableArray( [] ),
validYear : ko.observable(true),
init: function () {
var vm = dbo.monthlyEmployeeHoursModel;
dbo.reportsDataService.getUsedYears( function ( data ) {
vm.years( dbo.years )
vm.selectedYear( dbo.currentYear );
} );
vm.initModule();
},
initModule: function () {
var vm = dbo.monthlyEmployeeHoursModel;
vm.totalBudget( 0 );
vm.totalOwnRevenue( 0 );
vm.totalCosts( 0 );
vm.totalAvailableBudget( 0 );
vm.totalSaldo( 0 );
vm.totalWorkInProgress( 0 );
vm.totalEmployeeRevenues( 0 );
vm.totalAvailableRevenues( 0 )
vm.totalEmployeeHours( 0 );
vm.totalEmployeeAvailableHours( 0 );
vm.totalPerEmployee.removeAll();
vm.totalInvoicedYear.removeAll();
dbo.userDataService.getUniqueProjectEmployees( function ( data ) {
vm.uniqueEmployees.removeAll();
$.each( data, function ( i, p ) {
vm.uniqueEmployees.push( new vm.UniqueEmployee( p ) )
} );
} );
dbo.reportsDataService.getRecapProjects( function ( data ) {
vm.recap.removeAll();
vm.uniqueYears.removeAll();
$.each( data, function ( i, p ) {
if ( i == 0 ) {
$.each( p.invoiced, function ( y, q ) {
vm.uniqueYears.push( {year: q.year} );
} );
}
vm.recap.push( new vm.Project( p ) )
} );
vm.totalBudget( dbo.helpers.thousandSeparator( vm.totalBudget() ) );
vm.totalOwnRevenue( dbo.helpers.thousandSeparator( vm.totalOwnRevenue() ) );
vm.totalCosts( dbo.helpers.thousandSeparator( vm.totalCosts() ) );
vm.totalAvailableBudget( dbo.helpers.thousandSeparator( vm.totalAvailableBudget() ) );
vm.totalSaldo( dbo.helpers.thousandSeparator( vm.totalSaldo() ) );
vm.totalWorkInProgress( dbo.helpers.thousandSeparator( vm.totalWorkInProgress() ) );
vm.totalEmployeeRevenues( dbo.helpers.thousandSeparator( vm.totalEmployeeRevenues() ) );
vm.totalAvailableRevenues( dbo.helpers.thousandSeparator( vm.totalEmployeeRevenues() < 0 ? 0 :vm.totalEmployeeRevenues() ) );
vm.totalEmployeeHours( dbo.helpers.thousandSeparator( vm.totalEmployeeHours() ) );
_.each( vm.totalPerEmployee(), function ( p ) {
p.totalRevenue( dbo.helpers.thousandSeparator( p.totalRevenue() ) );
} );
_.each( vm.totalInvoicedYear(), function ( p ) {
p.totalInvoiced( dbo.helpers.thousandSeparator( p.totalInvoiced() ) );
} );
var chartData = [];
var chartLabels = [];
_.each( vm.totalPerEmployee(), function ( p ) {
chartData.push( Number( p.totalRevenue().replace( '.', '' ) ) );
chartLabels.push( p.fullname );
} );
var chartDataProjects = [];
var chartLabelsProjects = [];
var chartDataOwh = [];
var chartColorOwh = [];
_.each( vm.recap(), function ( p ) {
chartDataProjects.push( Number( p.totalEmployeeRevenues.replace( '.', '' ) ) );
chartLabelsProjects.push( p.projectname );
chartDataOwh.push( Number( p.workInProgress.replace( '.', '' ) ) );
chartColorOwh.push( Number( p.workInProgress.replace( '.', '' ) ) < 0 ? '#d53d24' : '#78be4b' );
} );
// dbo.charts.drawPie( 'recap-revenues', chartData, chartLabels, 'omzet per medewerker' );
// dbo.charts.drawPie( 'recap-revenues-project', chartDataProjects, chartLabelsProjects, 'omzet per project' );
// dbo.charts.drawHoursChart( 'recap-owh', chartDataOwh, chartLabelsProjects, 'onderhandenwerk per project', chartColorOwh );
} );
},
checkYear: function () {
var vm = dbo.monthlyEmployeeHoursModel;
if ( timeout ) {
clearTimeout( timeout );
timeout = null;
}
timeout = setTimeout( function () {
vm.validYear( true );
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.initModule();
}, 700 );
},
refreshTab: function () {
var vm = dbo.monthlyEmployeeHoursModel;
if ( vm.currentTab == false ) return;
dbo.reportsDataService.getEmployeeHours( vm.currentTab.id, vm.selectedYear(), function ( data ) {
vm.currentTab.myData( data );
vm.currentTab.totalJanuari( 0 );
vm.currentTab.totalFebruari( 0 );
vm.currentTab.totalMaart( 0 );
vm.currentTab.totalApril( 0 );
vm.currentTab.totalMei( 0 );
vm.currentTab.totalJuni( 0 );
vm.currentTab.totalJuli( 0 );
vm.currentTab.totalAugustus( 0 );
vm.currentTab.totalSeptember( 0 );
vm.currentTab.totalOktober( 0 );
vm.currentTab.totalNovember( 0 );
vm.currentTab.totalDecember( 0 );
vm.currentTab.totalTotal( 0 );
vm.currentTab.totalTotalOtheryears( 0 );
vm.currentTab.totalJanuariRevenue( 0 );
vm.currentTab.totalFebruariRevenue( 0 );
vm.currentTab.totalMaartRevenue( 0 );
vm.currentTab.totalAprilRevenue( 0 );
vm.currentTab.totalMeiRevenue( 0 );
vm.currentTab.totalJuniRevenue( 0 );
vm.currentTab.totalJuliRevenue( 0 );
vm.currentTab.totalAugustusRevenue( 0 );
vm.currentTab.totalSeptemberRevenue( 0 );
vm.currentTab.totalOktoberRevenue( 0 );
vm.currentTab.totalNovemberRevenue( 0 );
vm.currentTab.totalDecemberRevenue( 0 );
vm.currentTab.totalTotalRevenue( 0 );
vm.currentTab.totalTotalOtheryearsRevenue( 0 );
vm.currentTab.totalHoursChart = [];
vm.currentTab.totalHoursRevenueChart = [];
vm.currentTab.projectChart = [];
$.each( vm.currentTab.myData(), function ( i, q ) {
vm.currentTab.tarif( q.tarif );
vm.currentTab.totalJanuari( vm.currentTab.totalJanuari() + q.januari );
vm.currentTab.totalFebruari( vm.currentTab.totalFebruari() + q.februari );
vm.currentTab.totalMaart( vm.currentTab.totalMaart() + q.maart );
vm.currentTab.totalApril( vm.currentTab.totalApril() + q.april );
vm.currentTab.totalMei( vm.currentTab.totalMei() + q.mei );
vm.currentTab.totalJuni( vm.currentTab.totalJuni() + q.juni );
vm.currentTab.totalJuli( vm.currentTab.totalJuli() + q.juli );
vm.currentTab.totalAugustus( vm.currentTab.totalAugustus() + q.augustus );
vm.currentTab.totalSeptember( vm.currentTab.totalSeptember() + q.september );
vm.currentTab.totalOktober( vm.currentTab.totalOktober() + q.oktober );
vm.currentTab.totalNovember( vm.currentTab.totalNovember() + q.november );
vm.currentTab.totalDecember( vm.currentTab.totalDecember() + q.december );
vm.currentTab.totalTotal( vm.currentTab.totalTotal() + q.totalyear );
vm.currentTab.totalTotalOtheryears( vm.currentTab.totalTotalOtheryears() + q.totalotheryears );
vm.currentTab.totalJanuariRevenue( vm.currentTab.totalJanuariRevenue() + q.januariRevenue );
vm.currentTab.totalFebruariRevenue( vm.currentTab.totalFebruariRevenue() + q.februariRevenue );
vm.currentTab.totalMaartRevenue( vm.currentTab.totalMaartRevenue() + q.maartRevenue );
vm.currentTab.totalAprilRevenue( vm.currentTab.totalAprilRevenue() + q.aprilRevenue );
vm.currentTab.totalMeiRevenue( vm.currentTab.totalMeiRevenue() + q.meiRevenue );
vm.currentTab.totalJuniRevenue( vm.currentTab.totalJuniRevenue() + q.juniRevenue );
vm.currentTab.totalJuliRevenue( vm.currentTab.totalJuliRevenue() + q.juliRevenue );
vm.currentTab.totalAugustusRevenue( vm.currentTab.totalAugustusRevenue() + q.augustusRevenue );
vm.currentTab.totalSeptemberRevenue( vm.currentTab.totalSeptemberRevenue() + q.septemberRevenue );
vm.currentTab.totalOktoberRevenue( vm.currentTab.totalOktoberRevenue() + q.oktoberRevenue );
vm.currentTab.totalNovemberRevenue( vm.currentTab.totalNovemberRevenue() + q.novemberRevenue );
vm.currentTab.totalDecemberRevenue( vm.currentTab.totalDecemberRevenue() + q.decemberRevenue );
vm.currentTab.totalTotalRevenue( vm.currentTab.totalTotalRevenue() + q.totalyearRevenue );
vm.currentTab.totalTotalOtheryearsRevenue( vm.currentTab.totalTotalOtheryearsRevenue() + q.totalotheryearsRevenue );
vm.currentTab.projectChart.push( q.projectname );
vm.currentTab.totalHoursChart.push( q.totalhours );
vm.currentTab.totalHoursRevenueChart.push( q.totalhoursRevenue );
} );
vm.currentTab.chartData = [vm.currentTab.totalJanuari(), vm.currentTab.totalFebruari(), vm.currentTab.totalMaart(), vm.currentTab.totalApril(), vm.currentTab.totalMei(), vm.currentTab.totalJuni(), vm.currentTab.totalJuli(), vm.currentTab.totalAugustus(), vm.currentTab.totalSeptember(), vm.currentTab.totalOktober(), vm.currentTab.totalNovember(), vm.currentTab.totalDecember()];
vm.currentTab.chartRevenueData = [vm.currentTab.totalJanuariRevenue(), vm.currentTab.totalFebruariRevenue(), vm.currentTab.totalMaartRevenue(), vm.currentTab.totalAprilRevenue(), vm.currentTab.totalMeiRevenue(), vm.currentTab.totalJuniRevenue(), vm.currentTab.totalJuliRevenue(), vm.currentTab.totalAugustusRevenue(), vm.currentTab.totalSeptemberRevenue(), vm.currentTab.totalOktoberRevenue(), vm.currentTab.totalNovemberRevenue(), vm.currentTab.totalDecemberRevenue()];
// vm.drawCharts( vm.currentTab );
} );
},
drawCharts: function ( self ) {
if ( self.hourView() ) {
dbo.charts.drawHoursChart( 'hours-per-month-' + self.slug, self.chartData, dbo.monthLabels, 'uren per maand', '#f28f25' );
dbo.charts.drawHoursChart( 'hours-per-project-' + self.slug, self.totalHoursChart, self.projectChart, 'uren per project', '#0daef0' );
} else {
dbo.charts.drawHoursChart( 'revenue-per-month-' + self.slug, self.chartRevenueData, dbo.monthLabels, 'omzet per maand', '#f28f25' );
dbo.charts.drawHoursChart( 'revenue-per-project-' + self.slug, self.totalHoursRevenueChart, self.projectChart, 'omzet per project', '#0daef0' );
}
},
toggleHourView: function () {
this.hourView( !this.hourView() );
dbo.monthlyEmployeeHoursModel.drawCharts( this );
},
setActivetab: function ( tab ) {
var vm = dbo.monthlyEmployeeHoursModel;
$.each( vm.uniqueEmployees(), function ( i, p ) {
if ( tab == p.slug ) {
vm.currentTab = p;
vm.refreshTab();
}
} )
vm.sluggy( tab );
},
UniqueEmployee: function ( data ) {
var vm = dbo.monthlyEmployeeHoursModel;
var self = this;
self.id = data.id;
self.fullname = data.fullname;
self.slug = data.slug;
self.tarif = ko.observable( 0 );
self.totalJanuari = ko.observable( 0 );
self.totalFebruari = ko.observable( 0 );
self.totalMaart = ko.observable( 0 );
self.totalApril = ko.observable( 0 );
self.totalMei = ko.observable( 0 );
self.totalJuni = ko.observable( 0 );
self.totalJuli = ko.observable( 0 );
self.totalAugustus = ko.observable( 0 );
self.totalSeptember = ko.observable( 0 );
self.totalOktober = ko.observable( 0 );
self.totalNovember = ko.observable( 0 );
self.totalDecember = ko.observable( 0 );
self.totalTotal = ko.observable( 0 );
self.totalOtheryears = ko.observable( 0 );
self.totalTotalOtheryears = ko.observable( 0 );
self.totalJanuariRevenue = ko.observable( 0 );
self.totalFebruariRevenue = ko.observable( 0 );
self.totalMaartRevenue = ko.observable( 0 );
self.totalAprilRevenue = ko.observable( 0 );
self.totalMeiRevenue = ko.observable( 0 );
self.totalJuniRevenue = ko.observable( 0 );
self.totalJuliRevenue = ko.observable( 0 );
self.totalAugustusRevenue = ko.observable( 0 );
self.totalSeptemberRevenue = ko.observable( 0 );
self.totalOktoberRevenue = ko.observable( 0 );
self.totalNovemberRevenue = ko.observable( 0 );
self.totalDecemberRevenue = ko.observable( 0 );
self.totalTotalRevenue = ko.observable( 0 );
self.totalOtheryearsRevenue = ko.observable( 0 );
self.totalTotalOtheryearsRevenue = ko.observable( 0 );
self.hourView = ko.observable( true );
self.myData = ko.observableArray( [] );
},
Detail: function ( data ) {
this.test = data;
},
Project: function ( data ) {
var vm = dbo.monthlyEmployeeHoursModel;
var self = this;
self.projectnumber = data.projectnumber;
self.instroom = data.instroom;
self.uitstroom = data.uitstroom;
self.projectname = data.projectname;
self.name = data.name;
self.revenues = dbo.helpers.thousandSeparator( data.budget );
self.hours = data.hours;
self.totalEmpoloyeeRevenues = 0;
self.availableRevenue = data.own_revenue - data.projectEuros;
self.externCosts = dbo.helpers.thousandSeparator( data.projectcosts );
self.budget = dbo.helpers.thousandSeparator( data.budget );
self.ownRevenue = dbo.helpers.thousandSeparator( data.own_revenue );
self.budgetAvailable = dbo.helpers.thousandSeparator( data.budgetAvailable );
self.saldo = dbo.helpers.thousandSeparator( data.saldo );
self.employees = ko.observableArray( [] );
$.each( data.employees, function ( i, p ) {
self.employees.push( new vm.Employee( p ) );
if ( !self.totalEmployeeRevenues ) self.totalEmployeeRevenues = 0;
if ( !self.totalEmployeeHours ) self.totalEmployeeHours = 0;
} );
self.totalEmployeeRevenues = data.projectEuros;
self.totalEmployeeHours = data.projectHours;
self.hoursAvailable = data.hoursAvailable;
vm.totalAvailableRevenues( vm.totalAvailableRevenues() + self.availableRevenue );
vm.totalEmployeeRevenues( vm.totalEmployeeRevenues() + Number( self.totalEmployeeRevenues ) );
vm.totalEmployeeHours( vm.totalEmployeeHours() + Number( self.totalEmployeeHours ) );
vm.totalEmployeeAvailableHours( vm.totalEmployeeAvailableHours() + Number( self.hoursAvailable ) );
self.totalEmployeeRevenues = dbo.helpers.thousandSeparator( self.totalEmployeeRevenues );
self.availableRevenue = dbo.helpers.thousandSeparator( self.availableRevenue );
self.workInProgress = dbo.helpers.thousandSeparator( data.workInProgress );
self.hoursAvailable = data.hoursAvailable;
self.invoiced = ko.observableArray( [] );
$.each( data.invoiced, function ( i, p ) {
self.invoiced.push( {invoiced: dbo.helpers.thousandSeparator( p.invoiced )} );
} );
vm.setTotals( data );
},
setTotals: function ( data ) {
var vm = dbo.monthlyEmployeeHoursModel;
vm.totalBudget( vm.totalBudget() + Number( data.budget ) );
vm.totalOwnRevenue( vm.totalOwnRevenue() + Number( data.own_revenue ) );
vm.totalCosts( vm.totalCosts() + Number( data.projectcosts ) );
vm.totalAvailableBudget( vm.totalAvailableBudget() + Number( data.ownRevenueAvailable ) );
vm.totalSaldo( vm.totalSaldo() + Number( data.saldo ) );
vm.totalWorkInProgress( vm.totalWorkInProgress() + Number( data.workInProgress ) );
var hasTotalEmployees = true;
if ( vm.totalPerEmployee().length == 0 ) hasTotalEmployees = false;
_.each( data.employees, function ( p ) {
if ( !hasTotalEmployees ) {
vm.totalPerEmployee.push( {
id : p.id,
fullname : p.fullname,
totalRevenue : ko.observable( 0 ),
totalHours : ko.observable( 0 ),
totalAvailableHours: ko.observable( 0 )
} );
}
var a = _.find( vm.totalPerEmployee(), function ( o ) {
return o.id == p.id
} );
a.totalRevenue( a.totalRevenue() + Number( p.revenues ) );
a.totalHours( a.totalHours() + Number( p.hours ) );
a.totalAvailableHours( a.totalAvailableHours() + Number( p.availableHours ) );
} );
var hasTotalsOwpYear = true;
if ( vm.totalInvoicedYear().length == 0 ) hasTotalsOwpYear = false;
_.each( data.invoiced, function ( p ) {
if ( !hasTotalsOwpYear ) {
vm.totalInvoicedYear.push( {year: p.year, totalInvoiced: ko.observable( 0 )} );
}
var a = _.find( vm.totalInvoicedYear(), function ( o ) {
return o.year == p.year
} );
a.totalInvoiced( a.totalInvoiced() + Number( p.invoiced ) );
} );
},
Employee: function ( data ) {
this.fullname = data.fullname;
this.revenues = dbo.helpers.thousandSeparator( data.revenues );
this.hours = data.hours;
this.budget = data.budget;
this.availableHours = data.availableHours;
}
};
dbo.monthlyEmployeeHoursModel.init();
ko.applyBindings( dbo.monthlyEmployeeHoursModel, document.getElementById( "MONTHLYEMPLOYEEHOURS" ) );
}
}