/** * Created by Pensare Software. * User: Theo Weijmer * Date: 02/03/2018 * Time: 11:43 */ dbo.outgoinginvoicesInit = function () { if ( dbo.outgoinginvoicesModel !== undefined ) { } else { dbo.outgoinginvoicesModel = { initialize : null, years : ko.observableArray( [] ), selectedYear : ko.observable(), selectedMonthID: ko.observable(), projects : ko.observableArray( [] ), init: function () { var vm = dbo.outgoinginvoicesModel; 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( 0 ); vm.initialize = false; vm.initModule(); } ); }, initModule: function () { var vm = dbo.outgoinginvoicesModel; vm.refreshInvoiceDetails(); }, refreshInvoiceDetails: function () { var vm = dbo.outgoinginvoicesModel; if ( vm.initialize ) return; dbo.invoiceDataService.getInvoiceOverview( vm.selectedYear(), function ( data ) { vm.projects.removeAll(); _.each( data, function ( p ) { vm.projects.push( new vm.Project( p ) ); } ); } ); }, Project: function ( data ) { var openstaand = data.revenues - (Number( data.currentyear ) + Number( data.otheryear )); this.projectnumber = data.projectnumber; this.customername = data.customername; this.statusProject = Math.abs( openstaand ) > 2 ? 'OPEN' : 'CLOSED'; this.fullname = data.fullname; this.openstaand = dbo.helpers.numberWithPoints(Math.round(openstaand)); this.openstaandIncl = dbo.helpers.numberWithPoints(Math.round(openstaand * 1.21)); this.invoicedOtherYears = dbo.helpers.numberWithPoints(Math.round(data.otheryear)); this.invoicedCurentYear = dbo.helpers.numberWithPoints(Math.round(data.currentyear)); this.totalInvoiced = dbo.helpers.numberWithPoints(Math.round(data.currentyear) + Math.round(data.otheryear)); this.invoicedOtherYearsPayed = dbo.helpers.numberWithPoints(Math.round(data.otheryearpayed)); this.invoicedCurentYearPayed = dbo.helpers.numberWithPoints(Math.round(data.currentyearpayed)); this.totalInvoicedPayed = dbo.helpers.numberWithPoints(Math.round(data.currentyearpayed) + Math.round(data.otheryearpayed)); } } dbo.outgoinginvoicesModel.init(); ko.applyBindings( dbo.outgoinginvoicesModel, document.getElementById( "OUTGOINGINVOICES" ) ); } }