diff --git a/application/controllers/projects/OffersController.php b/application/controllers/projects/OffersController.php index 4e89923..5c764e5 100644 --- a/application/controllers/projects/OffersController.php +++ b/application/controllers/projects/OffersController.php @@ -63,7 +63,7 @@ class OffersController extends MY_Controller { { $removeOffer = new RemoveOffer( $offerID ); - if ( $removeOffer->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] ); + if ( $removeOffer->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] ); Offer::removeOffer( $offerID ); diff --git a/application/controllers/projects/ProjectsController.php b/application/controllers/projects/ProjectsController.php index ccac7d3..f2b75ab 100644 --- a/application/controllers/projects/ProjectsController.php +++ b/application/controllers/projects/ProjectsController.php @@ -256,28 +256,39 @@ class ProjectsController extends MY_Controller { Project::whereId( $projectID )->update( ['archive' => $status] ); } - public function removeProject( $projectID ) - { - $removeProject = new RemoveProject( $projectID ); - - if ( $removeProject->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] ); - - Project::removeProject( $projectID ); - - $this->json( ['result' => TRUE] ); - } - public function removeProjectemployee( $projectemployeeID ) { $removeProjectemployee = new RemoveProjectemployee( $projectemployeeID ); - if ( $removeProjectemployee->getAllowDelete() === FALSE ) return $this->json( ['result' => FALSE] ); + if ( $removeProjectemployee->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] ); Projectemployee::removeProjectemployee( $projectemployeeID ); $this->json( ['result' => TRUE] ); } + public function removeInvoice( $invoiceID ) + { + $removeInvoice = new RemoveInvoice( $invoiceID ); + + if ( $removeInvoice->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] ); + + Invoice::whereId( $invoiceID )->delete(); + + return $this->json( ['result' => TRUE] ); + } + + public function removeIncomingInvoice( $invoiceID ) + { +// $removeInvoice = new RemoveInvoice( $invoiceID ); +// +// if ( $removeInvoice->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] ); + + Projectcost::whereId( $invoiceID )->delete(); + + return $this->json( ['result' => TRUE] ); + } + public function removePayment( $paymentID ) { $removePayment = new RemovePayment( $paymentID ); @@ -322,4 +333,15 @@ class ProjectsController extends MY_Controller { $this->json( ['result' => TRUE] ); } + public function removeProject( $projectID ) + { + $removeProject = new RemoveProject( $projectID ); + + if ( $removeProject->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] ); + + Project::removeProject( $projectID ); + + $this->json( ['result' => TRUE] ); + } + } \ No newline at end of file diff --git a/application/libraries/deletions/RemoveInvoice.php b/application/libraries/deletions/RemoveInvoice.php new file mode 100644 index 0000000..c217630 --- /dev/null +++ b/application/libraries/deletions/RemoveInvoice.php @@ -0,0 +1,53 @@ +setInvoiceID( $invoiceID ); + + $this->handle(); + } + + public function getRemoveAllowed() + { + return $this->removeAllowed; + } + + private function setInvoiceID( $invoiceID ) + { + $this->invoiceID = $invoiceID; + } + + private function handle() + { + $this->setPayment(); + + $this->setRemoveAllowed(); + } + + private function setPayment() + { + $payments = Payment::whereInvoiceId( $this->invoiceID ); + + $this->payments = $payments->count() == 0 ? TRUE : FALSE; + } + + private function setRemoveAllowed() + { + if ( $this->payments === FALSE ) return $this->removeAllowed = FALSE; + + $this->removeAllowed = TRUE; + } + +} \ No newline at end of file diff --git a/application/libraries/deletions/RemoveInvoices.php b/application/libraries/deletions/RemoveInvoices.php new file mode 100644 index 0000000..afc9629 --- /dev/null +++ b/application/libraries/deletions/RemoveInvoices.php @@ -0,0 +1,46 @@ +setInvoiceID($invoiceID); + + $this->handle(); + } + + private function setInvoiceID( $invoiceID ) + { + $this->invoiceID = $invoiceID; + } + + private function handle() + { + $this->setPayments(); + + $this->setRemoveAllowed(); + } + + private function setPayments() + { + $payments = Payment::whereInvoiceId($this->invoiceID); + + $this->payments = $payments->count() == 0 ? TRUE : FALSE; + } + + private function setRemoveAllowed() + { + $this->removeAllowed = $this->payments; + } + +} \ No newline at end of file diff --git a/application/libraries/deletions/RemoveOffer.php b/application/libraries/deletions/RemoveOffer.php new file mode 100644 index 0000000..3d74389 --- /dev/null +++ b/application/libraries/deletions/RemoveOffer.php @@ -0,0 +1,52 @@ +setOfferID($offerID); + + $this->handle(); + } + + public function getRemoveAllowed() + { + return $this->removeAllowed; + } + + private function setOfferID( $offerID ) + { + $this->offerID = $offerID; + } + + private function handle() + { + $this->setProject(); + + $this->setRemoveAllowed(); + } + + private function setProject() + { + $offer = Offer::Find($this->offerID); + + $this->project = is_null($offer->project_id) ? TRUE : FALSE; + } + + private function setRemoveAllowed() + { + if( $this->project === FALSE ) return $this->removeAllowed = FALSE; + + $this->removeAllowed = TRUE; + } +} \ No newline at end of file diff --git a/application/libraries/deletions/RemoveProject.php b/application/libraries/deletions/RemoveProject.php new file mode 100644 index 0000000..c47dd1a --- /dev/null +++ b/application/libraries/deletions/RemoveProject.php @@ -0,0 +1,97 @@ +setProjectID( $projectID ); + + $this->handle(); + } + + public function getRemoveAllowed() + { + return $this->removeAllowed; + } + + private function setProjectID( $projectID ) + { + $this->projectID = $projectID; + } + + private function handle() + { + $this->setForecast(); + + $this->setInvoices(); + + $this->setProjectemployees(); + + $this->setReservations(); + + $this->setRemoveAllowed(); + + $this->setProjectCosts(); + } + + private function setForecast() + { + $forecast = Forecast::whereProjectId( $this->projectID ); + + $this->forecast = $forecast->count() == 0 ? TRUE : FALSE; + } + + private function setInvoices() + { + $invoices = Invoice::whereProjectId( $this->projectID ); + + $this->invoices = $invoices->count() == 0 ? TRUE : FALSE; + } + + private function setProjectemployees( ) + { + $setProjectemployees = Projectemployee::whereProjectId($this->projectID); + + $this->projectemployees = $setProjectemployees->count() == 0 ? TRUE : FALSE; + } + + private function setReservations( ) + { + $reservations = Reservation::whereProjectId($this->projectID); + + $this->reservations = $reservations->count() == 0 ? TRUE : FALSE; + } + + private function setProjectcosts( ) + { + $projectcosts = Projectcost::whereProjectId($this->projectID); + + $this->projectcosts = $projectcosts->count() == 0 ? TRUE : FALSE; + } + + private function setRemoveAllowed() + { + if( $this->forecast === false ) return $this->removeAllowed = FALSE; + if( $this->invoices === false ) return $this->removeAllowed = FALSE; + if( $this->projectemployees === false ) return $this->removeAllowed = FALSE; + if( $this->reservations === false ) return $this->removeAllowed = FALSE; + if( $this->projectcosts === false ) return $this->removeAllowed = FALSE; + + $this->removeAllowed = TRUE; + } + +} \ No newline at end of file diff --git a/application/libraries/deletions/RemoveProjectemployee.php b/application/libraries/deletions/RemoveProjectemployee.php new file mode 100644 index 0000000..9c8e56e --- /dev/null +++ b/application/libraries/deletions/RemoveProjectemployee.php @@ -0,0 +1,53 @@ +setProjectemployeeID( $projectemployeeID ); + + $this->handle(); + } + + public function getRemoveAllowed() + { + return $this->removeAllowed; + } + + private function setProjectemployeeID( $projectemployeeID ) + { + $this->projectemployeeID = $projectemployeeID; + } + + private function handle() + { + $this->setProjectHours(); + + $this->setRemoveAllowed(); + } + + private function setProjecthours() + { + $projecthours = Projecthour::whereProjectemployeeId($this->projectemployeeID); + + $this->projecthours = $projecthours->count() == 0 ?TRUE : FALSE; + } + + private function setRemoveAllowed() + { + if( $this->projecthours === false ) return $this->removeAllowed = FALSE; + + $this->removeAllowed = TRUE; + } + +} \ No newline at end of file diff --git a/application/libraries/projects/RemoveProject.php b/application/libraries/projects/RemoveProject.php deleted file mode 100644 index 409c125..0000000 --- a/application/libraries/projects/RemoveProject.php +++ /dev/null @@ -1,43 +0,0 @@ -setProjectID( $projectID ); - - $this->handle(); - } - - public function getAllowDelete() - { - return $this->allowDelete; - } - - private function setProjectID( $projectID ) - { - $this->projectID = $projectID; - } - - private function handle() - { - $this->checkForOffers(); - } - - private function checkForOffers() - { - $offers = Offer::whereProjectId($this->projectID); - - if( $offers->count() > 0 ) $this->allowDelete = FALSE; - } - -} \ No newline at end of file diff --git a/application/libraries/projects/RemoveProjectemployee.php b/application/libraries/projects/RemoveProjectemployee.php deleted file mode 100644 index 8350b68..0000000 --- a/application/libraries/projects/RemoveProjectemployee.php +++ /dev/null @@ -1,36 +0,0 @@ -setProjectemployeeID( $projectemployeeID ); - - $this->handle(); - } - - public function getAllowDelete() - { - return $this->allowDelete; - } - - private function setProjectemployeeID( $projectemployeeID ) - { - $this->projectemployeeID = $projectemployeeID; - } - - private function handle() - { - - } - -} \ No newline at end of file diff --git a/application/libraries/projects/offers/RemoveOffer.php b/application/libraries/projects/offers/RemoveOffer.php deleted file mode 100644 index 24b2d52..0000000 --- a/application/libraries/projects/offers/RemoveOffer.php +++ /dev/null @@ -1,36 +0,0 @@ -setOfferID( $userID ); - - $this->handle(); - } - - public function getAllowDelete() - { - return $this->allowDelete; - } - - private function setOfferID( $customerID ) - { - $this->offerID = $customerID; - } - - private function handle() - { - - } - -} \ No newline at end of file diff --git a/application/models/eloquent/Project.php b/application/models/eloquent/Project.php index 47862ed..e1840f9 100644 --- a/application/models/eloquent/Project.php +++ b/application/models/eloquent/Project.php @@ -80,6 +80,8 @@ class Project extends BaseModel { public static function removeProject( $projectID ) { + Offer::whereProjectId( $projectID )->update( ['project_id' => NULL] ); + Project::whereId( $projectID )->delete(); } diff --git a/application/models/eloquent/queries/Qinvoiceoverview.php b/application/models/eloquent/queries/Qinvoiceoverview.php index 7210d82..7146534 100644 --- a/application/models/eloquent/queries/Qinvoiceoverview.php +++ b/application/models/eloquent/queries/Qinvoiceoverview.php @@ -14,7 +14,7 @@ class Qinvoiceoverview { $sql = " SELECT PRJ.id, PRJ.projectnumber, PRJ.projectname, - (own_revenue + other_revenue ) AS revenues, + (own_revenue + other_revenue + OFF.costs ) AS revenues, CUS.name AS customername, SUM(IF( YEAR(invoicedate) = {$year}, invoiceamount* ((100 + VTS.vatrate)/100), 0)) AS currentyear, SUM(IF( YEAR(invoicedate) != {$year}, invoiceamount * ((100 + VTS.vatrate)/100), 0)) AS otheryear, diff --git a/application/models/projects/Invoices_model.php b/application/models/projects/Invoices_model.php index 0608f39..2bbdef1 100644 --- a/application/models/projects/Invoices_model.php +++ b/application/models/projects/Invoices_model.php @@ -27,7 +27,7 @@ class Invoices_model extends MY_Model { public function getOutstandingPerProject( $projectID ) { $this->sql = " - SELECT (own_revenue + other_revenue) AS totalrevenue, + SELECT (own_revenue + other_revenue + OFF.costs) AS totalrevenue, ROUND(SUM(INV.invoiceamount * ((100 + vatrate) / 100)), 0) AS totalinvoiced, ( SELECT SUM(paymentamount) PAYMENTAMOUNT diff --git a/application/views/modals/partials/_projectcosts.php b/application/views/modals/partials/_projectcosts.php index 4765b83..8277740 100644 --- a/application/views/modals/partials/_projectcosts.php +++ b/application/views/modals/partials/_projectcosts.php @@ -94,7 +94,7 @@ + data-bind="click:$root.removeProjectcosts"> diff --git a/application/views/modals/partials/_projectdashboard.php b/application/views/modals/partials/_projectdashboard.php index 07bf456..5998cc4 100644 --- a/application/views/modals/partials/_projectdashboard.php +++ b/application/views/modals/partials/_projectdashboard.php @@ -117,6 +117,13 @@
+ +
+

+ +

+
+

diff --git a/public/js/lib/dataservices/projectsDataservice.js b/public/js/lib/dataservices/projectsDataservice.js index 758fd4b..d20a1ae 100644 --- a/public/js/lib/dataservices/projectsDataservice.js +++ b/public/js/lib/dataservices/projectsDataservice.js @@ -121,6 +121,20 @@ dbo.projectDataService = { } ); }, + removeInvoice: function ( invoiceID, callback ) { + $.getJSON( 'index.php/projects/projectsController/removeInvoice/' + invoiceID ) + .done( function ( data ) { + callback( data ); + } ); + }, + + removeIncomingInvoice: function ( invoiceID, callback ) { + $.getJSON( 'index.php/projects/projectsController/removeIncomingInvoice/' + invoiceID ) + .done( function ( data ) { + callback( data ); + } ); + }, + removeProjectemployee: function ( projectemployeeID, callback ) { $.getJSON( 'index.php/projects/projectsController/removeProjectemployee/' + projectemployeeID ) .done( function ( data ) { diff --git a/public/js/lib/modals/projectModal.js b/public/js/lib/modals/projectModal.js index 40b611c..a864dd7 100644 --- a/public/js/lib/modals/projectModal.js +++ b/public/js/lib/modals/projectModal.js @@ -28,27 +28,28 @@ $( function () { 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(), - 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(), + 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(), @@ -554,7 +555,65 @@ $( function () { } else { tellMe( { title : 'fout bij verwijderen projectmedewerker', - message : 'de projectmedewerker kan niet worden verwijderd', + 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' } ); } @@ -775,7 +834,8 @@ $( function () { _.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.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 ) ); } ); diff --git a/public/js/lib/modules/projects/projectsModule.js b/public/js/lib/modules/projects/projectsModule.js index ad61372..3b52ea3 100644 --- a/public/js/lib/modules/projects/projectsModule.js +++ b/public/js/lib/modules/projects/projectsModule.js @@ -92,7 +92,7 @@ dbo.projectsInit = function () { } else { tellMe( { title : 'fout bij verwijderen project', - message : 'de project kan niet worden verwijderd', + message : 'de project kan niet worden verwijderd, verwijder eerst de gerelateerde gegevens (facturen, reserveringen, projectmedewerkers, prognoses) ', modalClass: 'modal-danger' } ); } diff --git a/public/js/lib/modules/reports/outgoingInvoices.js b/public/js/lib/modules/reports/outgoingInvoices.js index 6e5ef6e..90e00f4 100644 --- a/public/js/lib/modules/reports/outgoingInvoices.js +++ b/public/js/lib/modules/reports/outgoingInvoices.js @@ -104,8 +104,8 @@ dbo.outgoinginvoicesInit = function () { self.customername = data.customername; self.statusProject = Math.abs( openstaand ) > 2 ? 'OPEN' : 'CLOSED'; self.fullname = data.fullname; - self.revenues = dbo.helpers.numberWithPoints( data.revenues ); - self.totalInvoice = dbo.helpers.numberWithPoints( totalInvoice ); + 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 ) ); diff --git a/public/js/lib/services/offersService.js b/public/js/lib/services/offersService.js index 2b97622..737ad8c 100644 --- a/public/js/lib/services/offersService.js +++ b/public/js/lib/services/offersService.js @@ -69,7 +69,7 @@ dbo.offersService = { } else { tellMe( { title : 'fout bij verwijderen offerte', - message : 'de offerte kan niet worden verwijderd', + message : 'de offerte kan niet worden verwijderd, verwijder eerst het gerelateerde project', modalClass: 'modal-danger' } ); }