1129 lines
41 KiB
JavaScript
1129 lines
41 KiB
JavaScript
/**
|
|
* Created by Pensare Software.
|
|
* Offer: Theo Weijmer
|
|
* Date: 25/12/2017
|
|
* Time: 17:32
|
|
*/
|
|
|
|
$( function () {
|
|
var timeout;
|
|
dbo.editProjectModal = {
|
|
|
|
offers : ko.observableArray( [] ),
|
|
projectEmployees : ko.observableArray( [] ),
|
|
customers : ko.observableArray( [] ),
|
|
users : ko.observableArray( [] ),
|
|
invoices : ko.observableArray( [] ),
|
|
projecthours : ko.observableArray( [] ),
|
|
offerFiles : ko.observableArray( [] ),
|
|
offerComments : ko.observableArray( [] ),
|
|
projectFiles : ko.observableArray( [] ),
|
|
projectComments : ko.observableArray( [] ),
|
|
externals : ko.observableArray( [] ),
|
|
projectcosts : ko.observableArray( [] ),
|
|
vats : ko.observableArray( [] ),
|
|
availableEmployees : ko.observableArray( [] ),
|
|
forecasts : ko.observableArray( [] ),
|
|
reservations : ko.observableArray( [] ),
|
|
showProject : ko.observable( false ),
|
|
projectID : null,
|
|
callback : null,
|
|
customerID : ko.observable( null ),
|
|
projectnumber : ko.observable(),
|
|
projectleaderID : ko.observable(),
|
|
archive : ko.observable( false ),
|
|
startdate : ko.observable( null ),
|
|
enddate : ko.observable( null ),
|
|
vat_id : ko.observable(),
|
|
projectname : ko.observable(),
|
|
busy : false,
|
|
ownRevenue : ko.observable(),
|
|
otherRevenue : ko.observable(),
|
|
costs : ko.observable(),
|
|
projectname : ko.observable(),
|
|
years : ko.observableArray( dbo.years ),
|
|
months : ko.observableArray( dbo.monthArray ),
|
|
outstanding : ko.observable(),
|
|
documents : ko.observableArray( [] ),
|
|
comments : ko.observableArray( [] ),
|
|
activeTab : ko.observable(),
|
|
totalRevenues : ko.observable(),
|
|
totalInvoiced : ko.observable(),
|
|
totalRevenuesIncl: ko.observable(),
|
|
outstanding : ko.observable(),
|
|
outstandingInvoices: ko.observable(),
|
|
payed : ko.observable(),
|
|
totalForecast : ko.observable(),
|
|
toForecast : ko.observable(),
|
|
toInvoice : 0,
|
|
|
|
init: function () {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
vm.busy = true;
|
|
|
|
$( "#project-scroller" ).height( $( window ).height() - 100 );
|
|
|
|
dbo.customerDataService.getAllCustomers( 'F', function ( data ) {
|
|
vm.customers( data );
|
|
dbo.userDataService.getAllUsers( 'F', function ( data ) {
|
|
vm.users( data );
|
|
dbo.externalDataService.getAllExternals( 'F', function ( data ) {
|
|
vm.externals( data );
|
|
dbo.vatDataService.getVats( 'F', function ( data ) {
|
|
vm.vats( data );
|
|
|
|
vm.refreshAvailableEmployees( function () {
|
|
vm.refreshProject();
|
|
|
|
vm.activeTab( 'DASHBOARD' );
|
|
|
|
vm.busy = false;
|
|
} );
|
|
} );
|
|
} );
|
|
} );
|
|
} );
|
|
},
|
|
|
|
setActiveTab: function ( tab ) {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
vm.activeTab( tab );
|
|
},
|
|
|
|
togglePayments: function () {
|
|
this.showPayments( !this.showPayments() );
|
|
|
|
var showPayments = sessionStorage.showPayments || [];
|
|
|
|
if ( this.showPayments() ) {
|
|
showPayments.push( this.id );
|
|
} else {
|
|
var index = showPayments.indexOf( this.id );
|
|
showPayments.splice( index, 1 );
|
|
}
|
|
|
|
sessionStorage.setItem( "showPayment", showPayments );
|
|
},
|
|
|
|
toggleFromReservation: function () {
|
|
var vm = dbo.editProjectModal;
|
|
var self = this;
|
|
|
|
self.fromReservation( !self.fromReservation() );
|
|
|
|
vm.saveProjectCost(self);
|
|
},
|
|
|
|
editProjectemployee: function () {
|
|
var self = this;
|
|
var vm = dbo.editProjectModal;
|
|
$.each( vm.projectEmployees(), function ( i, p ) {
|
|
if ( p.id == self.id ) {
|
|
p.inEdit( !p.inEdit() );
|
|
} else {
|
|
p.inEdit( false );
|
|
}
|
|
} );
|
|
},
|
|
|
|
editInvoice: function () {
|
|
var self = this;
|
|
var vm = dbo.editProjectModal;
|
|
$.each( vm.invoices(), function ( i, p ) {
|
|
if ( p.id == self.id ) {
|
|
p.inEdit( !p.inEdit() );
|
|
} else {
|
|
p.inEdit( false );
|
|
}
|
|
} );
|
|
},
|
|
|
|
editPayment: function ( parent ) {
|
|
var self = this;
|
|
$.each( parent.payments(), function ( i, p ) {
|
|
console.log( p.invoice_id(), ' ', parent.id );
|
|
if ( p.id == self.id ) {
|
|
p.inEdit( !p.inEdit() );
|
|
} else {
|
|
p.inEdit( false );
|
|
}
|
|
} );
|
|
},
|
|
|
|
setHourtype: function ( status ) {
|
|
if ( !this.inEdit() ) return;
|
|
|
|
var vm = dbo.editProjectModal;
|
|
this.hourtype_id( status );
|
|
|
|
vm.saveProjecthour( this );
|
|
},
|
|
|
|
setPayment: function ( status ) {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
this.payed( status );
|
|
|
|
vm.saveReservation( this );
|
|
},
|
|
|
|
editProjecthour: function () {
|
|
var self = this;
|
|
var vm = dbo.editProjectModal;
|
|
$.each( vm.projecthours(), function ( i, p ) {
|
|
if ( p.id == self.id ) {
|
|
p.inEdit( !p.inEdit() );
|
|
} else {
|
|
p.inEdit( false );
|
|
}
|
|
} );
|
|
},
|
|
|
|
editProjectcosts: function () {
|
|
var self = this;
|
|
var vm = dbo.editProjectModal;
|
|
$.each( vm.projectcosts(), function ( i, p ) {
|
|
if ( p.id == self.id ) {
|
|
p.inEdit( !p.inEdit() );
|
|
} else {
|
|
p.inEdit( false );
|
|
}
|
|
} );
|
|
},
|
|
|
|
editForecast: function () {
|
|
var self = this;
|
|
var vm = dbo.editProjectModal;
|
|
$.each( vm.forecasts(), function ( i, p ) {
|
|
if ( p.id == self.id ) {
|
|
p.inEdit( !p.inEdit() );
|
|
} else {
|
|
p.inEdit( false );
|
|
}
|
|
} );
|
|
vm.toForecasting();
|
|
},
|
|
|
|
editReservation: function () {
|
|
var self = this;
|
|
var vm = dbo.editProjectModal;
|
|
$.each( vm.reservations(), function ( i, p ) {
|
|
if ( p.id == self.id ) {
|
|
p.inEdit( !p.inEdit() );
|
|
} else {
|
|
p.inEdit( false );
|
|
}
|
|
} );
|
|
},
|
|
|
|
newOffer: function () {
|
|
var vm = dbo.editProjectModal;
|
|
var service = dbo.offersService;
|
|
service.vm = dbo.editProjectModal;
|
|
|
|
service.newOffer( vm.projectID, vm.customerID() );
|
|
},
|
|
|
|
newInvoice: function () {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
var invoice = {
|
|
id : 0,
|
|
project_id : vm.projectID,
|
|
invoicenumber : '',
|
|
invoicedate : null,
|
|
invoiceamount : 0,
|
|
forecastamount: 0,
|
|
forecastdate : null,
|
|
inEdit : true,
|
|
showPayments : false,
|
|
payments : []
|
|
}
|
|
|
|
vm.invoices.push( new vm.Invoice( invoice ) );
|
|
},
|
|
|
|
newPayment: function () {
|
|
var vm = dbo.editProjectModal;
|
|
var self = this;
|
|
console.log( self );
|
|
var payment = {
|
|
id : 0,
|
|
invoice_id : self.id,
|
|
paymentdate : null,
|
|
paymentamount: 0,
|
|
inEdit : true
|
|
};
|
|
|
|
self.payments.push( new vm.Payment( payment ) );
|
|
},
|
|
|
|
newProjecthour: function () {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
var projecthour = {
|
|
id : 0,
|
|
projectemployee_id: null,
|
|
hourdate : null,
|
|
hours : 0,
|
|
hourtype_id : 1,
|
|
inEdit : true
|
|
};
|
|
|
|
vm.projecthours.push( new vm.Projecthour( projecthour ) );
|
|
},
|
|
|
|
newProjectcost: function () {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
var projectcost = {
|
|
id : 0,
|
|
external_id: null,
|
|
description: '',
|
|
date : null,
|
|
costs : 0,
|
|
payed : 0,
|
|
inEdit : true
|
|
};
|
|
|
|
vm.projectcosts.push( new vm.Projectcost( projectcost ) );
|
|
},
|
|
|
|
editOffer: function () {
|
|
var service = dbo.offersService;
|
|
service.vm = dbo.editProjectModal;
|
|
|
|
service.editOffer( this, false, false, true );
|
|
},
|
|
|
|
addProject: function ( callback ) {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
vm.callback = callback;
|
|
|
|
dbo.projectDataService.addProject( function ( data ) {
|
|
console.log( data );
|
|
vm.projectID = data;
|
|
|
|
vm.showProject( true );
|
|
|
|
vm.init();
|
|
} );
|
|
},
|
|
|
|
addProjectemployee: function () {
|
|
var vm = dbo.editProjectModal;
|
|
dbo.projectDataService.addProjectemployee( vm.projectID, function () {
|
|
vm.refreshProject();
|
|
} );
|
|
},
|
|
|
|
addForecast: function () {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
var forecast = {
|
|
id : 0,
|
|
project_id : vm.projectID,
|
|
year : dbo.currentYear,
|
|
month_id : dbo.currentMonth,
|
|
forecastamount: 0,
|
|
inEdit : true
|
|
};
|
|
|
|
vm.forecasts.push( new vm.Forecast( forecast ) );
|
|
},
|
|
|
|
addReservation: function () {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
var reservation = {
|
|
id : 0,
|
|
project_id : vm.projectID,
|
|
reservationamount : 0,
|
|
external_id : null,
|
|
inEdit : true,
|
|
invalidReservation: true
|
|
};
|
|
|
|
vm.reservations.push( new vm.Reservation( reservation ) );
|
|
},
|
|
|
|
editProject: function ( projectID, callback ) {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
vm.callback = callback;
|
|
vm.projectID = projectID;
|
|
|
|
vm.showProject( true );
|
|
|
|
vm.init();
|
|
},
|
|
|
|
saveProjectname: function () {
|
|
var vm = dbo.editProjectModal;
|
|
if ( timeout ) {
|
|
clearTimeout( timeout );
|
|
timeout = null;
|
|
}
|
|
timeout = setTimeout( function () {
|
|
vm.saveProject();
|
|
}, 700 );
|
|
},
|
|
|
|
saveProject: function () {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
if ( vm.busy ) return;
|
|
|
|
var submitDATA = {
|
|
id : vm.projectID,
|
|
customer_id : vm.customerID(),
|
|
projectleader_id: vm.projectleaderID(),
|
|
projectname : vm.projectname(),
|
|
startdate : vm.startdate(),
|
|
enddate : vm.enddate(),
|
|
vat_id : vm.vat_id()
|
|
}
|
|
|
|
dbo.projectDataService.saveProject( vm.projectID, submitDATA, function ( data ) {
|
|
vm.refreshProject();
|
|
// vm.projectID = data.projectID;
|
|
} );
|
|
},
|
|
|
|
changeProjectemployee: function () {
|
|
var vm = dbo.editProjectModal;
|
|
var self = this;
|
|
dbo.userDataService.getUser( this.employeeID(), function ( data ) {
|
|
self.tarif( data.hourlyrate );
|
|
|
|
vm.saveProjectemployee( self );
|
|
} );
|
|
},
|
|
|
|
saveProjectemployee: function ( self = false ) {
|
|
var vm = dbo.editProjectModal;
|
|
if ( !self ) self = this;
|
|
|
|
$.each( vm.users(), function ( i, p ) {
|
|
if ( self.employeeID == p.id ) self.fullname( p.fullname );
|
|
} );
|
|
|
|
if ( timeout ) {
|
|
clearTimeout( timeout );
|
|
timeout = null;
|
|
}
|
|
timeout = setTimeout( function () {
|
|
var submitDATA = {
|
|
id : self.id,
|
|
user_id: self.employeeID(),
|
|
tarif : self.tarif() ? self.tarif().toString().replace( ',', '.' ) : 0,
|
|
budget : self.budget() ? self.budget().toString().replace( ',', '.' ) : 0
|
|
}
|
|
|
|
dbo.projectDataService.saveProjectemployee( submitDATA, function () {
|
|
vm.refreshAvailableEmployees();
|
|
} );
|
|
}, 400 );
|
|
},
|
|
|
|
saveInvoice: function () {
|
|
var self = this;
|
|
|
|
var submitDATA = {
|
|
id : self.id,
|
|
project_id : self.project_id(),
|
|
invoicenumber : self.invoicenumber(),
|
|
invoicedate : self.invoicedate(),
|
|
invoiceamount : self.invoiceamount(),
|
|
forecastamount: self.forecastamount(),
|
|
forecastdate : self.forecastdate(),
|
|
vat_id : self.vat_id()
|
|
};
|
|
|
|
dbo.projectDataService.saveInvoice( submitDATA, function ( data ) {
|
|
if ( data.success ) self.id = data.invoiceID;
|
|
} );
|
|
|
|
},
|
|
|
|
savePayment: function () {
|
|
var self = this;
|
|
|
|
var submitDATA = {
|
|
id : self.id,
|
|
invoice_id : self.invoice_id(),
|
|
paymentdate : self.paymentdate(),
|
|
paymentamount: self.paymentamount()
|
|
};
|
|
|
|
dbo.projectDataService.savePayment( submitDATA, function ( data ) {
|
|
if ( data.success ) self.id = data.paymentID;
|
|
} );
|
|
},
|
|
|
|
saveProjecthour: function ( self = false ) {
|
|
if ( !self ) self = this;
|
|
|
|
if ( !self.projectemployee_id() ) return;
|
|
|
|
var submitDATA = {
|
|
id : self.id,
|
|
projectemployee_id: self.projectemployee_id(),
|
|
hourdate : self.hourdate(),
|
|
hourtype_id : self.hourtype_id(),
|
|
hours : self.hours()
|
|
};
|
|
|
|
dbo.projectDataService.saveProjecthour( submitDATA, function ( data ) {
|
|
console.log( data );
|
|
if ( data.success ) self.id = data.projecthourID;
|
|
} );
|
|
},
|
|
|
|
saveProjectcosts: function () {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
vm.saveProjectCost( this );
|
|
},
|
|
|
|
saveProjectCost: function ( self ) {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
var submitDATA = {
|
|
id : self.id,
|
|
project_id : vm.projectID,
|
|
external_id : self.external_id(),
|
|
description : self.description(),
|
|
date : self.date(),
|
|
costs : self.costs(),
|
|
payed : self.payed(),
|
|
from_reservation: self.fromReservation() ? 'T' : 'F'
|
|
};
|
|
|
|
dbo.projectDataService.saveProjectcost( submitDATA, function ( data ) {
|
|
if ( data.success ) self.id = data.projectcostID;
|
|
} );
|
|
},
|
|
|
|
saveForecast: function () {
|
|
var vm = dbo.editProjectModal;
|
|
var self = this;
|
|
|
|
var submitDATA = {
|
|
id : self.id,
|
|
project_id : self.project_id,
|
|
year : self.year(),
|
|
month_id : self.month_id(),
|
|
forecastamount: self.forecastamount()
|
|
}
|
|
|
|
dbo.projectDataService.saveForecast( submitDATA, function ( data ) {
|
|
if ( data.success ) self.id = data.forecastID;
|
|
vm.toForecasting();
|
|
} );
|
|
},
|
|
|
|
saveReservation: function ( self = false ) {
|
|
var vm = dbo.editProjectModal;
|
|
if ( !self ) self = this;
|
|
|
|
if ( !self.external_id ) {
|
|
self.invalidReservation( true );
|
|
return;
|
|
}
|
|
|
|
var submitDATA = {
|
|
id : self.id,
|
|
project_id : self.project_id,
|
|
external_id : self.external_id(),
|
|
reservationamount: self.reservationamount()
|
|
}
|
|
|
|
dbo.projectDataService.saveReservation( submitDATA, function ( data ) {
|
|
if ( data.success ) {
|
|
self.invalidReservation( false );
|
|
self.id = data.reservationID;
|
|
}
|
|
} );
|
|
},
|
|
|
|
removeProjectemployee: function () {
|
|
var vm = dbo.editProjectModal;
|
|
var self = this;
|
|
|
|
tellMe( {
|
|
title : 'verwijderen projectmedewerker',
|
|
message : 'weet u zeker dat u de projectmedewerker wilt verwijderen, dit kan niet ongedaan worden gemaakt',
|
|
notify : true,
|
|
noText : 'nee verwijder de projectmedewerker niet',
|
|
yesText : 'ja verwijder de projectmedewerker',
|
|
modalClass: 'modal-warning'
|
|
}, function ( response ) {
|
|
console.log( response );
|
|
if ( response ) {
|
|
dbo.projectDataService.removeProjectemployee( self.id, function ( data ) {
|
|
if ( data.result ) {
|
|
vm.refreshProject();
|
|
} else {
|
|
tellMe( {
|
|
title : 'fout bij verwijderen projectmedewerker',
|
|
message : 'de projectmedewerker kan niet worden verwijderd, verwijder eerst alle uren behorende bij deze medewerker bij dit project',
|
|
modalClass: 'modal-danger'
|
|
} );
|
|
}
|
|
} );
|
|
}
|
|
} );
|
|
},
|
|
|
|
removeInvoice: function () {
|
|
var vm = dbo.editProjectModal;
|
|
var self = this;
|
|
|
|
tellMe( {
|
|
title : 'verwijderen factuur',
|
|
message : 'weet u zeker dat u deze factuur wilt verwijderen, dit kan niet ongedaan worden gemaakt',
|
|
notify : true,
|
|
noText : 'nee verwijder de factuur niet',
|
|
yesText : 'ja verwijder de factuur',
|
|
modalClass: 'modal-warning'
|
|
}, function ( response ) {
|
|
console.log( response );
|
|
if ( response ) {
|
|
dbo.projectDataService.removeInvoice( self.id, function ( data ) {
|
|
if ( data.result ) {
|
|
vm.refreshProject();
|
|
} else {
|
|
tellMe( {
|
|
title : 'fout bij verwijderen factuur',
|
|
message : 'de factuur kan niet worden verwijderd, verwijder eerst alle betalingen op deze factuur',
|
|
modalClass: 'modal-danger'
|
|
} );
|
|
}
|
|
} );
|
|
}
|
|
} );
|
|
},
|
|
|
|
removeProjectcosts: function () {
|
|
var vm = dbo.editProjectModal;
|
|
var self = this;
|
|
|
|
tellMe( {
|
|
title : 'verwijderen inkomende factuur',
|
|
message : 'weet u zeker dat u deze inkomende factuur wilt verwijderen, dit kan niet ongedaan worden gemaakt',
|
|
notify : true,
|
|
noText : 'nee verwijder de inkomende factuur niet',
|
|
yesText : 'ja verwijder de inkomende factuur',
|
|
modalClass: 'modal-warning'
|
|
}, function ( response ) {
|
|
console.log( response );
|
|
if ( response ) {
|
|
dbo.projectDataService.removeIncomingInvoice( self.id, function ( data ) {
|
|
if ( data.result ) {
|
|
vm.refreshProject();
|
|
} else {
|
|
tellMe( {
|
|
title : 'fout bij verwijderen inkomende factuur',
|
|
message : 'de inkomende factuur kan niet worden verwijderd',
|
|
modalClass: 'modal-danger'
|
|
} );
|
|
}
|
|
} );
|
|
}
|
|
} );
|
|
},
|
|
|
|
removeOffer: function () {
|
|
var vm = dbo.editProjectModal;
|
|
var self = this;
|
|
|
|
tellMe( {
|
|
title : 'verwijderen offerte',
|
|
message : 'weet u zeker dat u de offerte wilt verwijderen, dit kan niet ongedaan worden gemaakt',
|
|
notify : true,
|
|
noText : 'nee verwijder de offerte niet',
|
|
yesText : 'ja verwijder de offerte',
|
|
modalClass: 'modal-warning'
|
|
}, function ( response ) {
|
|
console.log( response );
|
|
if ( response ) {
|
|
dbo.offerDataService.removeOffer( self.id, function ( data ) {
|
|
if ( data.result ) {
|
|
vm.refreshProject();
|
|
} else {
|
|
tellMe( {
|
|
title : 'fout bij verwijderen offerte',
|
|
message : 'de offerte kan niet worden verwijderd',
|
|
modalClass: 'modal-danger'
|
|
} );
|
|
}
|
|
} );
|
|
}
|
|
} );
|
|
},
|
|
|
|
removePayment: function () {
|
|
var vm = dbo.editProjectModal;
|
|
var self = this;
|
|
|
|
tellMe( {
|
|
title : 'verwijderen betaling',
|
|
message : 'weet u zeker dat u de betaling wilt verwijderen, dit kan niet ongedaan worden gemaakt',
|
|
notify : true,
|
|
noText : 'nee verwijder de betaling niet',
|
|
yesText : 'ja verwijder de betaling',
|
|
modalClass: 'modal-warning'
|
|
}, function ( response ) {
|
|
console.log( response );
|
|
if ( response ) {
|
|
dbo.projectDataService.removePayment( self.id, function ( data ) {
|
|
if ( data.result ) {
|
|
vm.refreshProject();
|
|
} else {
|
|
tellMe( {
|
|
title : 'fout bij verwijderen betaling',
|
|
message : 'de betaling kan niet worden verwijderd',
|
|
modalClass: 'modal-danger'
|
|
} );
|
|
}
|
|
} );
|
|
}
|
|
} );
|
|
},
|
|
|
|
removeProjecthour: function () {
|
|
var vm = dbo.editProjectModal;
|
|
var self = this;
|
|
|
|
tellMe( {
|
|
title : 'verwijderen projectuur',
|
|
message : 'weet u zeker dat u de projectuur wilt verwijderen, dit kan niet ongedaan worden gemaakt',
|
|
notify : true,
|
|
noText : 'nee verwijder de projectuur niet',
|
|
yesText : 'ja verwijder de projectuur',
|
|
modalClass: 'modal-warning'
|
|
}, function ( response ) {
|
|
console.log( response );
|
|
if ( response ) {
|
|
dbo.projectDataService.removeProjecthour( self.id, function ( data ) {
|
|
if ( data.result ) {
|
|
vm.refreshProject();
|
|
} else {
|
|
tellMe( {
|
|
title : 'fout bij verwijderen projectuur',
|
|
message : 'de projectuur kan niet worden verwijderd',
|
|
modalClass: 'modal-danger'
|
|
} );
|
|
}
|
|
} );
|
|
}
|
|
} );
|
|
},
|
|
|
|
removeForecast: function () {
|
|
var vm = dbo.editProjectModal;
|
|
var self = this;
|
|
|
|
tellMe( {
|
|
title : 'verwijderen prognose',
|
|
message : 'weet u zeker dat u deze prognose wilt verwijderen, dit kan niet ongedaan worden gemaakt',
|
|
notify : true,
|
|
noText : 'nee verwijder prognose niet',
|
|
yesText : 'ja verwijder de prognose',
|
|
modalClass: 'modal-warning'
|
|
}, function ( response ) {
|
|
console.log( response );
|
|
if ( response ) {
|
|
dbo.projectDataService.removeForecast( self.id, function ( data ) {
|
|
if ( data.result ) {
|
|
vm.refreshProject();
|
|
} else {
|
|
tellMe( {
|
|
title : 'fout bij verwijderen prognose',
|
|
message : 'de prognose kan niet worden verwijderd',
|
|
modalClass: 'modal-danger'
|
|
} );
|
|
}
|
|
} );
|
|
}
|
|
} );
|
|
},
|
|
|
|
removeReservation: function () {
|
|
var vm = dbo.editProjectModal;
|
|
var self = this;
|
|
|
|
tellMe( {
|
|
title : 'verwijderen reservering',
|
|
message : 'weet u zeker dat u deze reservering wilt verwijderen, dit kan niet ongedaan worden gemaakt',
|
|
notify : true,
|
|
noText : 'nee verwijder reservering niet',
|
|
yesText : 'ja verwijder de reservering',
|
|
modalClass: 'modal-warning'
|
|
}, function ( response ) {
|
|
console.log( response );
|
|
if ( response ) {
|
|
dbo.projectDataService.removeReservation( self.id, function ( data ) {
|
|
if ( data.result ) {
|
|
vm.refreshProject();
|
|
} else {
|
|
tellMe( {
|
|
title : 'fout bij verwijderen reserevring',
|
|
message : 'de reservering kan niet worden verwijderd',
|
|
modalClass: 'modal-danger'
|
|
} );
|
|
}
|
|
} );
|
|
}
|
|
} );
|
|
},
|
|
|
|
closeProject: function () {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
vm.showProject( false );
|
|
|
|
vm.callback();
|
|
},
|
|
|
|
validateNumber: function ( field ) {
|
|
this[field]( dbo.helpers.validateNumber( this[field](), true ) );
|
|
},
|
|
|
|
refreshAvailableEmployees: function ( callback ) {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
dbo.projectDataService.getAvailableEmployees( vm.projectID, function ( data ) {
|
|
vm.availableEmployees( data );
|
|
|
|
if ( typeof(callback) == 'function' ) callback();
|
|
} );
|
|
},
|
|
|
|
refreshProject: function () {
|
|
var vm = dbo.editProjectModal;
|
|
vm.busy = true;
|
|
|
|
dbo.projectDataService.getProject( vm.projectID, function ( data ) {
|
|
var revenues = Number(data.offer.own_revenue) + Number(data.offer.other_revenue) + Number(data.offer.costs);
|
|
var totalRevenuesIncl = Math.round( (revenues * (Number( data.vat.vatrate ) + 100)) / 100 );
|
|
|
|
vm.id = data.id
|
|
vm.projectleaderID( data.projectleader_id );
|
|
vm.customerID( data.customer_id );
|
|
vm.startdate( dbo.helpers.mysql2date( data.startdate ) );
|
|
vm.enddate( dbo.helpers.mysql2date( data.enddate ) );
|
|
vm.projectnumber( data.projectnumber );
|
|
vm.projectname( data.projectname );
|
|
vm.vat_id( data.vat_id );
|
|
vm.totalRevenuesIncl( dbo.helpers.numberWithPoints( totalRevenuesIncl ) );
|
|
vm.totalInvoiced( dbo.helpers.numberWithPoints( Math.round( Number( data.invoiceDetails.totalinvoiced ) ) ) );
|
|
vm.outstanding( dbo.helpers.numberWithPoints( Math.round( Number( totalRevenuesIncl ) ) - Math.round( Number( data.invoiceDetails.totalinvoiced ) ) ) );
|
|
vm.outstandingInvoices( dbo.helpers.numberWithPoints( Math.round( Number( data.invoiceDetails.totalinvoiced ) ) - Math.round( Number( data.invoiceDetails.payed ) ) ) );
|
|
vm.payed( dbo.helpers.numberWithPoints( Math.round( Number( data.invoiceDetails.payed ) ) ) );
|
|
vm.toInvoice = Math.round( totalRevenuesIncl - Number( data.invoiceDetails.totalinvoiced ) );
|
|
|
|
vm.projectEmployees.removeAll();
|
|
vm.projecthours.removeAll();
|
|
|
|
vm.ownRevenue( dbo.helpers.numberWithPoints( Math.round( Number( data.offer.own_revenue ) ) ) );
|
|
vm.otherRevenue( dbo.helpers.numberWithPoints( Math.round( Number( data.offer.other_revenue ) ) ) );
|
|
vm.costs(dbo.helpers.numberWithPoints( Math.round( Number( data.offer.costs ) ) ) );
|
|
vm.totalRevenues( dbo.helpers.numberWithPoints( Math.round( revenues ) ) );
|
|
|
|
|
|
_.each( data.projectemployees, function ( p ) {
|
|
vm.projectEmployees.push( new vm.Projectemployee( p ) );
|
|
} );
|
|
|
|
_.each( data.projectemployees, function ( p ) {
|
|
var fullname = p.user ? p.user.fullname : '#NB';
|
|
$.each( p.projecthours, function ( b, q ) {
|
|
vm.projecthours.push( new vm.Projecthour( q, fullname ) );
|
|
} );
|
|
} );
|
|
|
|
vm.projectcosts.removeAll();
|
|
_.each( data.projectcosts, function ( p ) {
|
|
vm.projectcosts.push( new vm.Projectcost( p ) );
|
|
} );
|
|
|
|
vm.invoices.removeAll();
|
|
_.each( data.invoices, function ( p ) {
|
|
vm.invoices.push( new vm.Invoice( p ) );
|
|
} );
|
|
|
|
vm.forecasts.removeAll();
|
|
_.each( data.forecasts, function ( p ) {
|
|
vm.forecasts.push( new vm.Forecast( p ) );
|
|
} );
|
|
|
|
vm.toForecasting();
|
|
|
|
vm.reservations.removeAll();
|
|
_.each( data.reservations, function ( p ) {
|
|
vm.reservations.push( new vm.Reservation( p ) );
|
|
} );
|
|
|
|
vm.refreshDocuments();
|
|
|
|
vm.busy = false;
|
|
|
|
// dbo.charts.drawHoursVsBudget( 340, 230, 'hours-vs-budget' );
|
|
// dbo.charts.drawInvoicesVsPayed( 36000, 24000, 11000, 'invoice-vs-payed' );
|
|
} );
|
|
},
|
|
|
|
toForecasting: function () {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
vm.totalForecast( 0 );
|
|
vm.toForecast( vm.toInvoice );
|
|
_.each( vm.forecasts(), function ( p ) {
|
|
vm.totalForecast( vm.totalForecast() + Number( p.forecastamount() ) );
|
|
vm.toForecast( vm.toForecast() - Number( p.forecastamount() ) );
|
|
} );
|
|
vm.toForecast( dbo.helpers.numberWithPoints( Number( vm.toForecast() ) ) );
|
|
vm.totalForecast( dbo.helpers.numberWithPoints( Number( vm.totalForecast() ) ) );
|
|
},
|
|
|
|
Projectemployee: function ( data ) {
|
|
var self = this;
|
|
|
|
self.id = data.id;
|
|
self.employeeID = ko.observable( data.user_id );
|
|
self.fullname = ko.observable( data.user ? data.user.fullname : '#NB' );
|
|
self.tarif = ko.observable( data.tarif ? data.tarif : 0 );
|
|
self.budget = ko.observable( data.budget ? data.budget : 0 );
|
|
self.inEdit = ko.observable( sessionStorage.editEmployee == data.id );
|
|
},
|
|
|
|
Projecthour: function ( data, fullname ) {
|
|
var self = this;
|
|
var vm = dbo.editProjectModal;
|
|
|
|
var inEdit = sessionStorage.Projecthour == data.id;
|
|
if ( !inEdit ) inEdit = data.inEdit || false;
|
|
|
|
self.id = data.id;
|
|
self.fullname = ko.observable( fullname );
|
|
self.projectemployee_id = ko.observable( data.projectemployee_id );
|
|
self.hourdate = ko.observable( dbo.helpers.mysql2date( data.hourdate ) );
|
|
self.hours = ko.observable( data.hours );
|
|
self.hourtype_id = ko.observable( data.hourtype_id );
|
|
self.inEdit = ko.observable( inEdit );
|
|
|
|
self.revenue = ko.pureComputed( function () {
|
|
if ( !self.projectemployee_id() ) return 0;
|
|
var tarif = dbo.helpers.findArrayElement( 'id', 'tarif', self.projectemployee_id(), vm.projectEmployees() )();
|
|
|
|
if ( isNaN( tarif ) ) return 0;
|
|
if ( isNaN( self.hours() ) ) return 0;
|
|
if ( self.hourtype_id() != 1 ) return 0;
|
|
|
|
return (tarif * self.hours()).toFixed( 0 );
|
|
} );
|
|
},
|
|
|
|
Projectcost: function ( data ) {
|
|
var self = this;
|
|
|
|
self.id = data.id;
|
|
self.external_id = ko.observable( data.external_id );
|
|
self.contactperson = ko.observable( data.external ? data.external.contactperson : '' );
|
|
self.description = ko.observable( data.description );
|
|
self.date = ko.observable( dbo.helpers.mysql2date( data.date ) );
|
|
self.costs = ko.observable( data.costs );
|
|
self.payed = ko.observable( data.payed );
|
|
self.inEdit = ko.observable( data.inEdit || false );
|
|
self.fromReservation = ko.observable( data.from_reservation == 'T' ? true : false );
|
|
|
|
this.toPay = ko.pureComputed( function () {
|
|
if ( isNaN( self.costs() ) ) return 0;
|
|
if ( isNaN( self.payed() ) ) return 0;
|
|
|
|
return self.costs() - self.payed();
|
|
} )
|
|
},
|
|
|
|
Invoice: function ( data ) {
|
|
var vm = dbo.editProjectModal;
|
|
var self = this;
|
|
var inEdit = sessionStorage.editInvoice == data.id;
|
|
if ( !inEdit ) inEdit = data.inEdit || false;
|
|
|
|
self.id = data.id;
|
|
self.project_id = ko.observable( data.project_id );
|
|
self.invoicenumber = ko.observable( data.invoicenumber );
|
|
self.invoicedate = ko.observable( dbo.helpers.mysql2date( data.invoicedate ) );
|
|
self.invoiceamount = ko.observable( data.invoiceamount.toFixed( 0 ) );
|
|
self.forecastamount = ko.observable( data.forecastamount.toFixed( 0 ) );
|
|
self.forecastdate = ko.observable( dbo.helpers.mysql2date( data.forecastdate ) );
|
|
self.vat_id = ko.observable( data.vat_id );
|
|
|
|
self.inEdit = ko.observable( inEdit );
|
|
|
|
self.inclBtw = ko.pureComputed( function () {
|
|
if ( !self.vat_id() ) return self.invoiceamount();
|
|
|
|
return (Number( self.invoiceamount() ) + (self.invoiceamount() *
|
|
(dbo.helpers.findArrayElement( 'id', 'vatrate', self.vat_id(), this.vats() ) / 100))).toFixed( 0 );
|
|
}, dbo.editProjectModal );
|
|
|
|
self.showPayments = ko.observable( data.showPayments || false );
|
|
if ( sessionStorage.showPayment == data.id ) self.showPayments( true );
|
|
|
|
self.payments = ko.observableArray( [] );
|
|
$.each( data.payments, function ( i, p ) {
|
|
self.payments.push( new vm.Payment( p, self.invoicenumber ) );
|
|
} );
|
|
|
|
self.outstanding = ko.pureComputed( function () {
|
|
var payed = 0
|
|
$.each( self.payments(), function ( i, p ) {
|
|
payed += Number( p.paymentamount() );
|
|
} );
|
|
return (self.inclBtw() - payed).toFixed( 0 );
|
|
} );
|
|
},
|
|
|
|
Payment: function ( data ) {
|
|
var inEdit = sessionStorage.editPayment == data.id;
|
|
if ( !inEdit ) inEdit = data.inEdit || false;
|
|
|
|
this.id = data.id;
|
|
this.invoice_id = ko.observable( data.invoice_id );
|
|
this.paymentdate = ko.observable( dbo.helpers.mysql2date( data.paymentdate ) );
|
|
this.paymentamount = ko.observable( data.paymentamount );
|
|
this.inEdit = ko.observable( inEdit );
|
|
},
|
|
|
|
Forecast: function ( data ) {
|
|
this.id = data.id;
|
|
this.project_id = data.project_id;
|
|
this.year = ko.observable( data.year );
|
|
this.month_id = ko.observable( data.month_id );
|
|
this.forecastamount = ko.observable( data.forecastamount );
|
|
this.inEdit = ko.observable( data.inEdit || false );
|
|
},
|
|
|
|
Reservation: function ( data ) {
|
|
console.log( data );
|
|
this.id = data.id;
|
|
this.project_id = data.project_id;
|
|
this.reservationamount = ko.observable( data.reservationamount );
|
|
this.external_id = ko.observable( data.external_id );
|
|
this.inEdit = ko.observable( data.inEdit || false );
|
|
this.invalidReservation = ko.observable( data.invalidReservation || false );
|
|
},
|
|
|
|
addDocument: function ( data, evt ) {
|
|
var vm = dbo.editProjectModal;
|
|
uploadFile( evt.target.files[0], vm.projectID, function () {
|
|
vm.refreshDocuments();
|
|
} );
|
|
},
|
|
|
|
addComment: function () {
|
|
var vm = dbo.editProjectModal;
|
|
dbo.commentsDataService.addComment( vm.selectedRowID(), vm.tableName, function ( commentID ) {
|
|
dbo.commentModel.showComment( commentID, function () {
|
|
vm.refreshComments();
|
|
} )
|
|
} );
|
|
},
|
|
|
|
editComment: function () {
|
|
var vm = dbo.editProjectModal;
|
|
dbo.commentModel.showComment( this.id, function () {
|
|
vm.refreshComments();
|
|
} );
|
|
},
|
|
|
|
downloadDocument: function () {
|
|
window.open( 'index.php/projects/documentsController/downloadDocument/' + this.id );
|
|
},
|
|
|
|
refreshComments: function () {
|
|
var vm = dbo.editProjectModal;
|
|
|
|
dbo.commentsDataService.getComments( vm.selectedRowID(), vm.tableName, function ( data ) {
|
|
vm.comments.removeAll();
|
|
console.log( data );
|
|
$.each( data, function ( i, p ) {
|
|
vm.comments.push( new vm.Comment( p ) );
|
|
} );
|
|
} );
|
|
},
|
|
|
|
refreshDocuments: function () {
|
|
var vm = dbo.editProjectModal;
|
|
console.log( vm.projectID );
|
|
dbo.documentsDataService.getdocuments( vm.projectID, function ( data ) {
|
|
vm.documents.removeAll();
|
|
|
|
$.each( data, function ( i, p ) {
|
|
vm.documents.push( new vm.Document( p ) );
|
|
} )
|
|
} );
|
|
},
|
|
|
|
Comment: function ( data ) {
|
|
this.id = data.id;
|
|
this.comment_date = data.comment_date;
|
|
this.fullname = data.user.fullname;
|
|
this.comment = ko.observable( data.comment );
|
|
},
|
|
|
|
Document: function ( data ) {
|
|
this.id = data.id;
|
|
this.originalname = data.originalname;
|
|
this.uploaddate = data.uploaddate;
|
|
this.fullname = data.user.fullname;
|
|
}
|
|
|
|
};
|
|
|
|
dbo.editProjectModal.totalHours = ko.pureComputed( function () {
|
|
var vm = dbo.editProjectModal;
|
|
var totalHours = 0
|
|
|
|
$.each( vm.projecthours(), function ( i, p ) {
|
|
if ( p.hourtype_id() == 1 ) {
|
|
totalHours += Number( p.hours() );
|
|
}
|
|
} );
|
|
return totalHours.toFixed( 2 );
|
|
} );
|
|
|
|
dbo.editProjectModal.totalRevenue = ko.pureComputed( function () {
|
|
var vm = dbo.editProjectModal;
|
|
var totalRevenue = 0
|
|
|
|
$.each( vm.projecthours(), function ( i, p ) {
|
|
if ( p.hourtype_id() == 1 ) {
|
|
totalRevenue += Number( p.revenue() );
|
|
}
|
|
} );
|
|
return totalRevenue.toFixed( 0 );
|
|
} );
|
|
|
|
dbo.editProjectModal.totalBudget = ko.pureComputed( function () {
|
|
var vm = dbo.editProjectModal;
|
|
var totalBudget = 0;
|
|
|
|
$.each( vm.projectEmployees(), function ( i, p ) {
|
|
totalBudget += Number( p.budget() );
|
|
} );
|
|
return totalBudget;
|
|
} );
|
|
|
|
ko.applyBindings( dbo.editProjectModal, document.getElementById( 'project-modal' ) );
|
|
} );
|
|
|
|
|