diff options
author | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2016-03-26 21:47:48 +0100 |
---|---|---|
committer | Ludovic Pouzenc <ludovic@pouzenc.fr> | 2016-03-26 21:47:48 +0100 |
commit | ec4787db8a89bac903ab3f4ef2565cf78ceb384b (patch) | |
tree | d0e9d9cf719d0336c6582d21f6af85ba9c0a2ce9 /generator/after-bake/src | |
parent | e00900e121dbf32468bda4db3cbc0de44b2baa8b (diff) | |
download | chd_gestion-ec4787db8a89bac903ab3f4ef2565cf78ceb384b.zip chd_gestion-ec4787db8a89bac903ab3f4ef2565cf78ceb384b.tar.gz chd_gestion-ec4787db8a89bac903ab3f4ef2565cf78ceb384b.tar.bz2 |
Service/terminate : implement it.
Diffstat (limited to 'generator/after-bake/src')
-rw-r--r-- | generator/after-bake/src/Controller/ServicesController.php | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/generator/after-bake/src/Controller/ServicesController.php b/generator/after-bake/src/Controller/ServicesController.php index a3a034b..0371623 100644 --- a/generator/after-bake/src/Controller/ServicesController.php +++ b/generator/after-bake/src/Controller/ServicesController.php @@ -256,4 +256,27 @@ class ServicesController extends AppController $this->set(compact('service', 'new_service')); $this->set('_serialize', ['service', 'new_service']); } + + public function terminate($id = null) + { + $this->request->allowMethod(['post']); + $service = $this->Services->get($id); + if ( $service ) { + if ( $service->service_statut_id === 4 /* Actif CHD */ ) { + $patch = array( + 'service_statut_id' => 6, /* Actif CHD */ + 'date_fin' => new DateTime('now'), + ); + $service = $this->Services->patchEntity($service, $patch); + if ($this->Services->save($service)) { + $this->Flash->success(__('The service has been saved.')); + } else { + $this->Flash->error(__('The service could not be saved. Please, try again.')); + } + } else { + $this->Flash->error(__('Can\'t terminate the service. Bad service state.')); + } + return $this->redirect(['controller' => 'Adherents', 'action' => 'view', $service->adherent_id]); + } + } } |