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 @@