From 4954d6fccae4a3438ae94a8601543ac66a01a7f8 Mon Sep 17 00:00:00 2001 From: Theo Weijmer Date: Mon, 11 Jun 2018 08:17:01 +0200 Subject: [PATCH] Fix --- application/models/eloquent/Project.php | 10 ++++++---- public/js/lib/modals/projectModal.js | 19 ++++++++----------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/application/models/eloquent/Project.php b/application/models/eloquent/Project.php index e1840f9..31a3426 100644 --- a/application/models/eloquent/Project.php +++ b/application/models/eloquent/Project.php @@ -16,6 +16,11 @@ class Project extends BaseModel { return $this->hasMany( 'Offer' ); } + public function offer() + { + return $this->hasOne( 'Offer' ); + } + public function projectemployees() { return $this->hasMany( 'Projectemployee' ); @@ -105,10 +110,7 @@ class Project extends BaseModel { 'projectleader' => function ( $q ) { $q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ); }] ) - ->with( [ - 'offers' => function ( $q ) { - $q->whereArchive( 'F' ); - }] ) + ->with( 'offer' ) ->with( [ 'projectemployees.user' => function ( $q ) { $q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ); diff --git a/public/js/lib/modals/projectModal.js b/public/js/lib/modals/projectModal.js index a864dd7..38e3e32 100644 --- a/public/js/lib/modals/projectModal.js +++ b/public/js/lib/modals/projectModal.js @@ -804,7 +804,6 @@ $( function () { vm.projectnumber( data.projectnumber ); vm.projectname( data.projectname ); vm.vat_id( data.vat_id ); - vm.totalRevenues( dbo.helpers.numberWithPoints( Math.round( Number( data.invoiceDetails.totalrevenue ) ) ) ); 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 ) ) ) ); @@ -814,6 +813,14 @@ $( function () { 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 ) ) ) ); + var revenues = Number(data.offer.own_revenue) + Number(data.offer.other_revenue) + Number(data.offer.costs); + vm.totalRevenues( dbo.helpers.numberWithPoints( Math.round( revenues ) ) ); + + _.each( data.projectemployees, function ( p ) { vm.projectEmployees.push( new vm.Projectemployee( p ) ); } ); @@ -830,16 +837,6 @@ $( function () { vm.projectcosts.push( new vm.Projectcost( p ) ); } ); - vm.offers.removeAll(); - _.each( data.offers, function ( p, i ) { - if ( i == 0 ) { - vm.ownRevenue( dbo.helpers.numberWithPoints( Math.round( Number( p.own_revenue ) ) ) ); - vm.otherRevenue( dbo.helpers.numberWithPoints( Math.round( Number( p.other_revenue ) ) ) ) - vm.costs(dbo.helpers.numberWithPoints( Math.round( Number( p.costs ) ) ) ) - } - vm.offers.push( new dbo.offersService.Offer( p ) ); - } ); - vm.invoices.removeAll(); _.each( data.invoices, function ( p ) { vm.invoices.push( new vm.Invoice( p ) );