From b0a866ba11e2a0fa3b9f9afcf4c8df379719806a Mon Sep 17 00:00:00 2001 From: Theo Weijmer Date: Sun, 5 Aug 2018 10:48:53 +0200 Subject: [PATCH] Diversen nav mail Peter --- .../controllers/beheer/vatController.php | 13 ++++ application/core/MY_Controller.php | 16 ++++- application/libraries/deletions/RemoveVat.php | 65 +++++++++++++++++++ application/views/pages/vat_view.php | 10 ++- public/js/lib/dataservices/vatDataService.js | 7 ++ public/js/lib/modules/beheer/vatModule.js | 22 ++++++- .../modules/projects/employeehoursModule.js | 2 +- 7 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 application/libraries/deletions/RemoveVat.php 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 @@
+ - % + + + % +
- - + + diff --git a/public/js/lib/dataservices/vatDataService.js b/public/js/lib/dataservices/vatDataService.js index a172f42..0a21f71 100644 --- a/public/js/lib/dataservices/vatDataService.js +++ b/public/js/lib/dataservices/vatDataService.js @@ -23,6 +23,13 @@ dbo.vatDataService = { saveVat: function ( vatID, vatrate ) { $.post( 'index.php/beheer/vatController/saveVat/' + vatID, {vatrate: vatrate} ); + }, + + removeVat: function ( vatID, callback ) { + $.getJSON( 'index.php/beheer/vatController/removeVat/' + vatID ) + .done( function (data) { + callback(data); + } ); } } diff --git a/public/js/lib/modules/beheer/vatModule.js b/public/js/lib/modules/beheer/vatModule.js index f82421c..98a7e77 100644 --- a/public/js/lib/modules/beheer/vatModule.js +++ b/public/js/lib/modules/beheer/vatModule.js @@ -11,6 +11,8 @@ dbo.vatInit = function () { if ( dbo.vatModel !== undefined ) { + dbo.vatModel.refreshVat(); + } else { dbo.vatModel = { @@ -37,7 +39,7 @@ dbo.vatInit = function () { _.each( data, function ( p ) { vm.vats.push( new vm.Vat( p ) ); - } ) + } ); } ); }, @@ -65,6 +67,24 @@ dbo.vatInit = function () { }, removeVat: function () { + dbo.vatDataService.removeVat( this.id, function(data){ + if( data.result ){ + dbo.vatModel.refreshVat(); + + var message = 'BTW succesvol verwijderd'; + var modalClass = 'modal-success'; + }else{ + var message ='BTW is in gebruik en kan niet worden verwijderd'; + var modalClass= 'modal-danger'; + } + tellMe( { + title : 'verwijderen BTW', + message : message, + notify : false, + modalClass: modalClass + }); + } ); + } } diff --git a/public/js/lib/modules/projects/employeehoursModule.js b/public/js/lib/modules/projects/employeehoursModule.js index 4c54e84..dda04be 100644 --- a/public/js/lib/modules/projects/employeehoursModule.js +++ b/public/js/lib/modules/projects/employeehoursModule.js @@ -72,7 +72,7 @@ dbo.employeehoursInit = function () { hourdate : employeeHour ? employeeHour.hourdate() : null, hourtype_id: employeeHour ? employeeHour.hourtype_id() : 9, project_id : employeeHour ? employeeHour.projectID() : null, - hours : employeeHour ? employeeHour.hours() : 0, + hours : 0, inEdit : true };