summaryrefslogtreecommitdiff
path: root/generator/after-bake/src/Controller/ServicesController.php
diff options
context:
space:
mode:
Diffstat (limited to 'generator/after-bake/src/Controller/ServicesController.php')
-rw-r--r--generator/after-bake/src/Controller/ServicesController.php23
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]);
+ }
+ }
}