145 lines
6.5 KiB
JavaScript
145 lines
6.5 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(),
|
|
|
|
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() ) ) );
|
|
} );
|
|
},
|
|
|
|
resetModel: function () {
|
|
var vm = dbo.outgoinginvoicesModel;
|
|
vm.totalToInvoice( 0 );
|
|
vm.totalToInvoiceFuture( 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( data.revenues );
|
|
self.totalInvoice = dbo.helpers.numberWithPoints( totalInvoice );
|
|
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 ) );
|
|
self.missingForecast =
|
|
dbo.helpers.numberWithPoints( totalInvoice - totalInvoiced - data.otherforecast );
|
|
|
|
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 )) );
|
|
},
|
|
|
|
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" ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
} |