110 lines
3.9 KiB
JavaScript
110 lines
3.9 KiB
JavaScript
/**
|
|
* Created by Pensare Software.
|
|
* User: Theo Weijmer
|
|
* Date: 31/10/2019
|
|
* Time: 14:31
|
|
*/
|
|
|
|
dbo.dashboardInit = function () {
|
|
|
|
if (dbo.dashboardModel !== undefined) {
|
|
|
|
dbo.dashboardModel.init()
|
|
|
|
} else {
|
|
dbo.dashboardModel = {
|
|
|
|
owpThisYear : ko.observable(null),
|
|
owpNextYear : ko.observable(null),
|
|
owpTotal : ko.observable(null),
|
|
revenuesNextyear : ko.observable(null),
|
|
totalRevenues : ko.observable(null),
|
|
outstanding : ko.observable(null),
|
|
toInvoice : ko.observable(null),
|
|
openCosts : ko.observable(null),
|
|
revenues : ko.observable(null),
|
|
revenues : ko.observable(null),
|
|
revenueCurrentYear : ko.observable(null),
|
|
revenuesThisYear : ko.observable(null),
|
|
billingOverview : ko.observableArray([]),
|
|
showInvoiceOverview: ko.observable(false),
|
|
openInvoices : ko.observable(null),
|
|
invoiced : ko.observable(null),
|
|
minimumRevenues : ko.observable(null),
|
|
totalChance : ko.observable(null),
|
|
|
|
init: function () {
|
|
var self = dbo.dashboardModel
|
|
dbo.dashboardDataservice.getOwhp(function (data) {
|
|
var outstandings = self.getOutstandingTotal(data.outstandings)
|
|
var revCurYear = Number(data.currentFinancialYear) + Number(data.totalOwp)
|
|
|
|
self.owpThisYear(dbo.helpers.thousandSeparator(data.currentFinancialYear))
|
|
self.owpNextYear(dbo.helpers.thousandSeparator(data.owpNextyear))
|
|
self.owpTotal(dbo.helpers.thousandSeparator(data.totalOwp))
|
|
self.revenuesNextyear(dbo.helpers.thousandSeparator(data.revenuesNextyear))
|
|
self.totalRevenues(dbo.helpers.thousandSeparator(data.totalRevenues))
|
|
self.minimumRevenues(dbo.helpers.thousandSeparator(data.currentFinancialYear + data.revenuesThisYear))
|
|
self.invoiced(dbo.helpers.thousandSeparator(data.invoiced))
|
|
self.openInvoices(dbo.helpers.thousandSeparator(outstandings.openInvoices))
|
|
self.toInvoice(dbo.helpers.thousandSeparator(outstandings.toInvoice))
|
|
self.totalChance(dbo.helpers.thousandSeparator(data.totalChance))
|
|
|
|
self.revenueCurrentYear(dbo.helpers.thousandSeparator(revCurYear))
|
|
self.revenuesThisYear(dbo.helpers.thousandSeparator(data.revenuesThisYear))
|
|
dbo.reservationsDataservice.getReservations(function (data) {
|
|
var openCosts = 0
|
|
$.each(data, function (i, p) {
|
|
openCosts += Number(p.other_revenue) - Number(p.payed)
|
|
})
|
|
self.openCosts(dbo.helpers.thousandSeparator(openCosts))
|
|
|
|
var revenues = outstandings.openInvoices + outstandings.toInvoice - openCosts
|
|
revenues = Math.round(revenues / 1.21)
|
|
self.revenues(dbo.helpers.thousandSeparator(revenues))
|
|
})
|
|
})
|
|
},
|
|
|
|
getOutstandingTotal: function (data) {
|
|
var self = dbo.dashboardModel
|
|
var openInvoices = 0
|
|
var toInvoice = 0
|
|
var costs = 0
|
|
var openCosts = 0
|
|
|
|
_.each(data, function (p) {
|
|
openInvoices += Number(p.invoiceToPay.replace('.', ''))
|
|
toInvoice += Number(p.needInvoice.replace('.', ''))
|
|
})
|
|
|
|
var revenues = (Number(open) + Number(toInvoice) - Number(openCosts)) / 1.21
|
|
return {
|
|
openInvoices: openInvoices,
|
|
toInvoice : toInvoice,
|
|
costs : costs,
|
|
revenues : Math.round(revenues),
|
|
openCosts : openCosts
|
|
}
|
|
},
|
|
invoiceOverview : function () {
|
|
var self = dbo.dashboardModel
|
|
|
|
self.showInvoiceOverview(!self.showInvoiceOverview())
|
|
},
|
|
Billing : function (data) {
|
|
console.log(data)
|
|
self.project = data.projectnumber + ' ' + data.projectname
|
|
self.invoiced = dbo.helpers.thousandSeparator(data.invoiced)
|
|
self.payedcosts = dbo.helpers.thousandSeparator(data.payedcosts)
|
|
self.openCosts = dbo.helpers.thousandSeparator(Number(data.invoiced) - Number(data.payedcosts))
|
|
self.archive = data.archive
|
|
}
|
|
}
|
|
|
|
dbo.dashboardModel.init()
|
|
|
|
ko.applyBindings(dbo.dashboardModel, document.getElementById('DASHBOARD'))
|
|
}
|
|
}
|