Spreadsheet

This commit is contained in:
2018-07-29 21:26:49 +02:00
parent 30535f7048
commit b86c3fc4b9
26 changed files with 1286 additions and 432 deletions
@@ -13,5 +13,9 @@ dbo.invoiceDataService = {
.done( function ( data ) {
callback( data );
} );
},
createSpreadsheet : function(year){
$.get( 'index.php/reports/reportsController/createInvoicesSpreadsheet/' + year )
}
};
+2
View File
@@ -48,6 +48,8 @@ $( function () {
vm[page]( true );
var func = page.toLowerCase() + 'Init';
console.log( func );
window.dbo[func]();
},
@@ -0,0 +1,220 @@
/**
* 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;
dbo.invoiceDataService.createSpreadsheet(vm.selectedYear());
}
}
dbo.invoicereport.init();
ko.applyBindings(
dbo.invoicereport, document.getElementById( "INVOICEREPORT" ) );
}
}
@@ -1,160 +0,0 @@
/**
* 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" ) );
}
}