From ec4787db8a89bac903ab3f4ef2565cf78ceb384b Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sat, 26 Mar 2016 21:47:48 +0100 Subject: Service/terminate : implement it. --- .../src/Controller/ServicesController.php | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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]); + } + } } -- cgit v1.1