diff --git a/application/controllers/beheer/vatController.php b/application/controllers/beheer/vatController.php index eb45a01..c20a59e 100644 --- a/application/controllers/beheer/vatController.php +++ b/application/controllers/beheer/vatController.php @@ -44,4 +44,17 @@ class vatController extends MY_Controller { $vatrate = $this->input->post( 'vatrate' ); Vat::whereId( $vatID )->update( ['vatrate' => $vatrate] ); } + + public function removeVat( $vatID ) + { + $removeVat = new RemoveVat($vatID); + + $allowRemove = $removeVat->getRemoveAllowed(); + + if( $allowRemove === FALSE ) return $this->json( ['result'=>FALSE]); + + Vat::whereId($vatID)->delete(); + + $this->json( ['result'=>TRUE]); + } } \ No newline at end of file diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php index 8a8f6ea..2eb6184 100644 --- a/application/core/MY_Controller.php +++ b/application/core/MY_Controller.php @@ -16,7 +16,7 @@ class MY_Controller extends CI_Controller { { parent::__construct(); - $this->version = '0.02.00'; + $this->version = '0.02.01'; $this->load->library( 'beheer/session/RetrieveUserSession' ); @@ -25,11 +25,25 @@ class MY_Controller extends CI_Controller { private function handle() { + $this->setSecureSite(); + $this->retrieveusersession->handle(); $this->user = $this->User_model->get( USERID ); } + public function setSecureSite() + { + if ( getenv( 'ENVIRONMENT' ) != 'production' ) return; + + if ( ! isset( $_SERVER["HTTPS"] ) || $_SERVER["HTTPS"] != "on" ) + { + header( "Location: " . getenv( 'APP_URL' ) ); + + exit; + } + } + function clean_input( $post ) { $value = $this->input->input_stream( $post, TRUE ); diff --git a/application/libraries/deletions/RemoveVat.php b/application/libraries/deletions/RemoveVat.php new file mode 100644 index 0000000..a36e38e --- /dev/null +++ b/application/libraries/deletions/RemoveVat.php @@ -0,0 +1,65 @@ +setVatID( $vatID ); + + $this->handle(); + } + + public function getRemoveAllowed() + { + return $this->removeAllowed; + } + + private function setVatID( $vatID ) + { + $this->vatID = $vatID; + } + + private function handle() + { + $this->setProject(); + + $this->setInvoices(); + + $this->setRemoveAllowed(); + } + + private function setProject() + { + $projects = Project::whereVatId( $this->vatID ); + + $this->projects = $projects->count() == 0 ? TRUE : FALSE; + } + + private function setInvoices() + { + $invoices = Invoice::whereVatId( $this->vatID ); + + $this->invoices = $invoices->count() == 0 ? TRUE : FALSE; + } + + private function setRemoveAllowed() + { + if ( $this->projects === FALSE ) return $this->removeAllowed = FALSE; + + if ( $this->invoices === FALSE ) return $this->removeAllowed = FALSE; + + $this->removeAllowed = TRUE; + } + +} \ No newline at end of file diff --git a/application/views/pages/vat_view.php b/application/views/pages/vat_view.php index 729ce79..b75e2df 100644 --- a/application/views/pages/vat_view.php +++ b/application/views/pages/vat_view.php @@ -12,16 +12,20 @@