221 lines
9.5 KiB
JavaScript
221 lines
9.5 KiB
JavaScript
/**
|
|
* Created by Pensare Software.
|
|
* User: Theo Weijmer
|
|
* Date: 02/03/2018
|
|
* Time: 11:43
|
|
*/
|
|
|
|
|
|
dbo.invoicereportInit = function () {
|
|
|
|
if ( dbo.invoicereport !== undefined ) {
|
|
|
|
dbo.invoicereport.initModule();
|
|
|
|
} else {
|
|
dbo.invoicereport = {
|
|
|
|
selectedYear : ko.observable(),
|
|
invoiceOverview : ko.observableArray( [] ),
|
|
forecasts : ko.observableArray( [] ),
|
|
monthForecasts : ko.observableArray( [] ),
|
|
monthPayments : ko.observableArray( [] ),
|
|
months : ko.observableArray( [] ),
|
|
monthTotals : ko.observableArray( [] ),
|
|
monthPaymentTotals : ko.observableArray( [] ),
|
|
validYear : ko.observable(),
|
|
invoiceTab : ko.observable(),
|
|
totalToInvoicingExcl : ko.observable(),
|
|
totalToInvoicingIncl : ko.observable(),
|
|
totalInvoicedOtherYears: ko.observable(),
|
|
totalInvoicedThisYear : ko.observable(),
|
|
invoicesTotal : ko.observable(),
|
|
needInvoice : ko.observable(),
|
|
forecastThisYear : ko.observable(),
|
|
forecastOtherYears : ko.observable(),
|
|
forecastRemaining : ko.observable(),
|
|
totalProjectPayments : ko.observable(),
|
|
|
|
init: function () {
|
|
var vm = dbo.invoicereport;
|
|
|
|
vm.selectedYear( (new Date()).getFullYear() );
|
|
vm.invoiceTab( 'invoice' );
|
|
vm.validYear( true );
|
|
vm.months( dbo.monthArray );
|
|
|
|
vm.initModule();
|
|
},
|
|
|
|
initModule: function () {
|
|
var vm = dbo.invoicereport;
|
|
|
|
vm.resetTotals();
|
|
|
|
dbo.invoiceDataService.getInvoiceOverview( vm.selectedYear(), function ( data ) {
|
|
vm.invoiceOverview( data.invoiceOverview );
|
|
vm.setInvoiceOverviewTotals( data.invoiceOverview );
|
|
|
|
vm.forecasts( data.forecasts );
|
|
vm.setForecastsTotals( data.forecasts );
|
|
|
|
vm.monthForecasts.removeAll();
|
|
_.each( data.monthForecasts, function ( p ) {
|
|
vm.monthForecasts.push( new vm.Monthforecast( p ) );
|
|
} );
|
|
_.each( vm.monthTotals(), function ( p ) {
|
|
p.forecastamount( dbo.helpers.thousandSeparator( p.forecastamount() ) );
|
|
} );
|
|
|
|
vm.monthPayments.removeAll();
|
|
_.each( data.monthPayments, function ( p ) {
|
|
vm.monthPayments.push( new vm.Monthpayment( p ) );
|
|
vm.totalProjectPayments( Number( vm.totalProjectPayments() ) + Number(p.totalProjectPayments.replace('.', '')) );
|
|
console.log( vm.totalProjectPayments() );
|
|
} );
|
|
vm.totalProjectPayments( dbo.helpers.thousandSeparator( vm.totalProjectPayments() ) );
|
|
_.each( vm.monthPaymentTotals(), function ( p ) {
|
|
p.paymentamount( dbo.helpers.thousandSeparator( p.paymentamount() ) );
|
|
} );
|
|
|
|
} );
|
|
},
|
|
|
|
resetTotals: function () {
|
|
var vm = dbo.invoicereport;
|
|
|
|
vm.totalToInvoicingExcl( 0 );
|
|
vm.totalToInvoicingIncl( 0 );
|
|
vm.totalInvoicedOtherYears( 0 );
|
|
vm.totalInvoicedThisYear( 0 );
|
|
vm.invoicesTotal( 0 );
|
|
vm.needInvoice( 0 );
|
|
vm.forecastThisYear( 0 );
|
|
vm.forecastOtherYears( 0 );
|
|
vm.forecastRemaining( 0 );
|
|
vm.totalProjectPayments( 0 );
|
|
|
|
for ( var i = 1; i <= 12; i++ ) {
|
|
vm.monthTotals.push( {monthID: i, forecastamount: ko.observable( 0 )} );
|
|
vm.monthPaymentTotals.push( {monthID: i, paymentamount: ko.observable( 0 )} );
|
|
}
|
|
},
|
|
|
|
setInvoiceOverviewTotals: function ( data ) {
|
|
var vm = dbo.invoicereport;
|
|
|
|
_.each( data, function ( p ) {
|
|
vm.totalToInvoicingExcl( vm.totalToInvoicingExcl() + Number( p.totalToInvoicingExcl.replace( '.', '' ) ) );
|
|
vm.totalToInvoicingIncl( vm.totalToInvoicingIncl() + Number( p.totalToInvoicingIncl.replace( '.', '' ) ) );
|
|
vm.totalInvoicedOtherYears( vm.totalInvoicedOtherYears() + Number( p.totalInvoicedOtherYears.replace( '.', '' ) ) );
|
|
vm.totalInvoicedThisYear( vm.totalInvoicedThisYear() + Number( p.totalInvoicedThisYear.replace( '.', '' ) ) );
|
|
vm.invoicesTotal( vm.invoicesTotal() + Number( p.invoicesTotal.replace( '.', '' ) ) );
|
|
vm.needInvoice( vm.needInvoice() + Number( p.needInvoice.replace( '.', '' ) ) );
|
|
} );
|
|
|
|
vm.totalToInvoicingExcl( dbo.helpers.thousandSeparator( vm.totalToInvoicingExcl() ) );
|
|
vm.totalToInvoicingIncl( dbo.helpers.thousandSeparator( vm.totalToInvoicingIncl() ) );
|
|
vm.totalInvoicedOtherYears( dbo.helpers.thousandSeparator( vm.totalInvoicedOtherYears() ) );
|
|
vm.totalInvoicedThisYear( dbo.helpers.thousandSeparator( vm.totalInvoicedThisYear() ) );
|
|
vm.invoicesTotal( dbo.helpers.thousandSeparator( vm.invoicesTotal() ) );
|
|
vm.needInvoice( dbo.helpers.thousandSeparator( vm.needInvoice() ) );
|
|
},
|
|
|
|
setForecastsTotals: function ( data ) {
|
|
var vm = dbo.invoicereport;
|
|
|
|
_.each( data, function ( p ) {
|
|
vm.forecastThisYear( vm.forecastThisYear() + Number( p.forecastThisYear.replace( '.', '' ) ) );
|
|
vm.forecastOtherYears( vm.forecastOtherYears() + Number( p.forecastOtherYears.replace( '.', '' ) ) );
|
|
vm.forecastRemaining( vm.forecastRemaining() + Number( p.forecastRemaining.replace( '.', '' ) ) );
|
|
} );
|
|
vm.forecastThisYear( dbo.helpers.thousandSeparator( vm.forecastThisYear() ) );
|
|
vm.forecastOtherYears( dbo.helpers.thousandSeparator( vm.forecastOtherYears() ) );
|
|
vm.forecastRemaining( dbo.helpers.thousandSeparator( vm.forecastRemaining() ) );
|
|
},
|
|
|
|
setForecastMonthsTotals: function ( data ) {
|
|
var vm = dbo.invoicereport;
|
|
|
|
_.each( data, function ( p ) {
|
|
_.each( p.forecastMonths(), function ( q ) {
|
|
vm.forecastMonths( vm.forecastMonths() + q );
|
|
} );
|
|
} );
|
|
},
|
|
|
|
checkYear: function () {
|
|
var vm = dbo.invoicereport;
|
|
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 ( page ) {
|
|
var vm = dbo.invoicereport;
|
|
|
|
vm.invoiceTab( page );
|
|
},
|
|
|
|
Monthforecast: function ( data ) {
|
|
var vm = dbo.invoicereport;
|
|
var self = this;
|
|
self.projectname = data.projectname;
|
|
self.customer = data.customer;
|
|
self.needInvoice = data.needInvoice;
|
|
self.forecastOtherYears = data.forecastOtherYears;
|
|
self.forecastRemaining = data.forecastRemaining;
|
|
|
|
self.forecastMonths = ko.observableArray( [] );
|
|
_.each( data.forecastMonths, function ( p, i ) {
|
|
self.forecastMonths.push( new vm.ForecastMonth( p ) );
|
|
_.each( vm.monthTotals(), function ( q ) {
|
|
if ( q.monthID == i ) q.forecastamount( Number( q.forecastamount() ) + p.forecastamount );
|
|
} );
|
|
} );
|
|
},
|
|
|
|
ForecastMonth: function ( data ) {
|
|
this.forecastamount = dbo.helpers.thousandSeparator( data.forecastamount );
|
|
},
|
|
|
|
Monthpayment: function ( data ) {
|
|
var vm = dbo.invoicereport;
|
|
var self = this;
|
|
self.projectname = data.projectname;
|
|
self.customer = data.customer;
|
|
self.totalProjectPayments = data.totalProjectPayments;
|
|
|
|
self.paymentMonths = ko.observableArray( [] );
|
|
_.each( data.monthPayments, function ( p, i ) {
|
|
self.paymentMonths.push( new vm.PaymentMonth( p ) );
|
|
_.each( vm.monthPaymentTotals(), function ( q ) {
|
|
if ( q.monthID == i ) q.paymentamount( Number( q.paymentamount() ) + p.paymentamount );
|
|
} );
|
|
} );
|
|
},
|
|
|
|
PaymentMonth: function ( data ) {
|
|
this.paymentamount = dbo.helpers.thousandSeparator( data.paymentamount );
|
|
},
|
|
|
|
createSpreadsheet:function(){
|
|
var vm = dbo.invoicereport;
|
|
var url = 'index.php/reports/reportsController/createInvoicesSpreadsheet/' + vm.selectedYear();
|
|
window.open(url, '_blank');
|
|
}
|
|
}
|
|
|
|
dbo.invoicereport.init();
|
|
|
|
ko.applyBindings(
|
|
dbo.invoicereport, document.getElementById( "INVOICEREPORT" ) );
|
|
|
|
|
|
}
|
|
|
|
|
|
} |