Files
dbois/public/js/lib/modules/reports/outgoingInvoices.js
T
2018-06-10 17:31:05 +02:00

160 lines
7.6 KiB
JavaScript

/**
* 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( [] ),
invoiceTab : ko.observable( 'invoice' ),
months : ko.observableArray( dbo.monthArray ),
totalToInvoice : ko.observable(),
totalToInvoiceFuture: ko.observable(),
initialize : null,
validYear : ko.observable(),
totalToInvoice : ko.observable(),
totalCurrentforecast: ko.observable(),
totalOtherforecast : ko.observable(),
totalMissingForecast: ko.observable(),
init: function () {
var vm = dbo.outgoinginvoicesModel;
vm.selectedYear( (new Date()).getFullYear() );
vm.selectedMonthID( 0 );
vm.validYear( true );
vm.initModule();
},
setActivetab: function ( tab ) {
var vm = dbo.outgoinginvoicesModel;
vm.invoiceTab( tab );
},
initModule: function () {
var vm = dbo.outgoinginvoicesModel;
vm.refreshInvoiceDetails();
},
checkYear: function () {
var vm = dbo.outgoinginvoicesModel;
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();
},
refreshInvoiceDetails: function () {
var vm = dbo.outgoinginvoicesModel;
vm.resetModel();
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 ) );
} );
vm.totalToInvoice( dbo.helpers.numberWithPoints( Math.round( vm.totalToInvoice() ) ) );
vm.totalToInvoiceFuture( dbo.helpers.numberWithPoints( Math.round( vm.totalToInvoiceFuture() ) ) );
vm.totalCurrentforecast( dbo.helpers.numberWithPoints( Math.round( vm.totalCurrentforecast() ) ) );
vm.totalOtherforecast( dbo.helpers.numberWithPoints( Math.round( vm.totalOtherforecast() ) ) );
vm.totalMissingForecast( dbo.helpers.numberWithPoints( Math.round( vm.totalMissingForecast() ) ) );
} );
},
resetModel: function () {
var vm = dbo.outgoinginvoicesModel;
vm.totalToInvoice( 0 );
vm.totalToInvoiceFuture( 0 );
vm.totalCurrentforecast( 0 );
vm.totalOtherforecast( 0 );
vm.totalMissingForecast( 0 );
},
Project: function ( data ) {
var vm = dbo.outgoinginvoicesModel;
var self = this;
var openstaand = data.revenues - (Number( data.currentyear ) + Number( data.otheryear ));
var totalInvoice = data.revenues * (1 + (data.vatrate / 100));
var totalInvoiced = Math.round( data.currentyear ) + Math.round( data.otheryear );
var totalInvoicedPayed = Math.round( data.currentyearpayed ) + Math.round( data.otheryearpayed );
var notPayed = totalInvoiced - totalInvoicedPayed;
self.projectnumber = data.projectnumber;
self.customername = data.customername;
self.statusProject = Math.abs( openstaand ) > 2 ? 'OPEN' : 'CLOSED';
self.fullname = data.fullname;
self.revenues = dbo.helpers.numberWithPoints( Number(data.revenues).toFixed(0) );
self.totalInvoice = dbo.helpers.numberWithPoints( Number(totalInvoice).toFixed(0) );
self.openstaand = dbo.helpers.numberWithPoints( Math.round( openstaand ) );
self.openstaandIncl = dbo.helpers.numberWithPoints( Math.round( openstaand * 1.21 ) );
self.invoicedOtherYears = dbo.helpers.numberWithPoints( Math.round( data.otheryear ) );
self.invoicedCurentYear = dbo.helpers.numberWithPoints( Math.round( data.currentyear ) );
self.totalInvoiced = dbo.helpers.numberWithPoints( totalInvoiced );
self.invoicedOtherYearsPayed = dbo.helpers.numberWithPoints( Math.round( data.otheryearpayed ) );
self.invoicedCurentYearPayed = dbo.helpers.numberWithPoints( Math.round( data.currentyearpayed ) );
self.totalInvoicedPayed = dbo.helpers.numberWithPoints( Math.round( totalInvoicedPayed ) );
self.notPayed = dbo.helpers.numberWithPoints( Math.round( notPayed ) );
self.toInvoice = dbo.helpers.numberWithPoints( Math.round( totalInvoice - totalInvoiced ) );
self.toInvoiceFuture = dbo.helpers.numberWithPoints( Math.round( totalInvoice - totalInvoiced - Number( data.currentforecast ) ) );
self.currentforecast = dbo.helpers.numberWithPoints( Math.round( data.currentforecast ) );
self.otherforecast = dbo.helpers.numberWithPoints( Math.round( data.otherforecast ) );
var missingForcast = Math.round( totalInvoice - totalInvoiced - data.otherforecast - data.currentforecast );
console.log( missingForcast );
self.missingForecast = dbo.helpers.numberWithPoints( missingForcast );
self.months = ko.observableArray( [] );
_.each( data.months, function ( p ) {
self.months.push( new vm.Month( p ) );
if ( !vm['forecast' + p.month] ) vm['forecast' + p.month] = ko.observable( 0 );
vm['forecast' + p.month]( Number( vm['forecast' + p.month]() ) + Number( p.forecastamount ) );
if ( !vm['payment' + p.month] ) vm['payment' + p.month] = ko.observable( 0 );
vm['payment' + p.month]( Number( vm['payment' + p.month]() ) + Number( p.paymentamount ) );
} );
vm.totalToInvoice( vm.totalToInvoice() + (totalInvoice - totalInvoiced) );
vm.totalToInvoiceFuture( vm.totalToInvoiceFuture() + (totalInvoice - totalInvoiced - Number( data.currentforecast )) );
vm.totalCurrentforecast( Number( vm.totalCurrentforecast() ) + Number( data.currentforecast ) );
vm.totalOtherforecast( Number( vm.totalOtherforecast() ) + Number( data.otherforecast ) );
vm.totalMissingForecast( Number( vm.totalMissingForecast() ) + Number( missingForcast ) );
},
Month: function ( data ) {
this.forecastamount = dbo.helpers.numberWithPoints( Number( data.forecastamount ).toFixed( 0 ) );
this.paymentamount = dbo.helpers.numberWithPoints( Number( data.paymentamount ).toFixed( 0 ) );
}
}
dbo.outgoinginvoicesModel.init();
ko.applyBindings(
dbo.outgoinginvoicesModel, document.getElementById( "OUTGOINGINVOICES" ) );
}
}