diff --git a/app/Controller/FichesController.php b/app/Controller/FichesController.php index 5d65d1df2a9e3585b006cf055330b4d9f4c60044..80a7a6164d311270e044099941334c357f11ce97 100644 --- a/app/Controller/FichesController.php +++ b/app/Controller/FichesController.php @@ -765,6 +765,9 @@ class FichesController extends AppController $this->redirect($this->Referers->get()); } +// debug($this->request->data); +// die; + $success = true; $this->Fiche->begin(); @@ -853,13 +856,19 @@ class FichesController extends AppController $initialisationMode = true; } + $initialisationRecu = false; + if ($etatFiche['EtatFiche']['etat_id'] === EtatFiche::TRAITEMENT_INITIALISE_RECU) { + $initialisationRecu = true; + } + $success = $this->WebdpoFiche->saveWithVirtualFields( $data, $formulaireFields, $formulaireOptions, $formulaireOLD['Formulaire']['oldformulaire'], false, - $initialisationMode + $initialisationMode, + $initialisationRecu ); if ($success == true) { @@ -1058,22 +1067,17 @@ class FichesController extends AppController $typages = $this->_typages(); - $etatFiche = $this->EtatFiche->find('first', [ - 'conditions' => [ - 'fiche_id' => $id, - 'actif' => true - ], - 'fields' => [ - 'etat_id' - ] - ]); - $initialisationMode = false; - if ($etatFiche['EtatFiche']['etat_id'] === EtatFiche::INITIALISATION_TRAITEMENT) { + if ($etatTraitement['EtatFiche']['etat_id'] === EtatFiche::INITIALISATION_TRAITEMENT) { $initialisationMode = true; } - $this->set(compact('formulaireOLD', 'typages', 'initialisationMode')); + $initialisationRecu = false; + if ($etatTraitement['EtatFiche']['etat_id'] === EtatFiche::TRAITEMENT_INITIALISE_RECU) { + $initialisationRecu = true; + } + + $this->set(compact('formulaireOLD', 'typages', 'initialisationMode', 'initialisationRecu')); $this->set('formulaire_id', $fiche['Fiche']['form_id']); $this->view = 'add'; diff --git a/app/Model/WebdpoFiche.php b/app/Model/WebdpoFiche.php index c0a4a9b361a050f0ce09b2125ad6b3509900dd1f..858122e118f38ec3de2d67c34cb7960698adf69e 100644 --- a/app/Model/WebdpoFiche.php +++ b/app/Model/WebdpoFiche.php @@ -395,7 +395,7 @@ class WebdpoFiche extends AppModel { // --------------------------------------------------------------------- ]; - public function saveWithVirtualFields($data, $champs, $formulaireOptions, $formulaireOLD, $actionAdd, $initialisationMode = false) + public function saveWithVirtualFields($data, $champs, $formulaireOptions, $formulaireOLD, $actionAdd, $initialisationMode = false, $initialisationRecu = false) { $success = true; $Fiche = ClassRegistry::init('Fiche'); @@ -493,11 +493,16 @@ class WebdpoFiche extends AppModel { if ($actionAdd === false) { $fieldsToKeep = array_merge ($fieldsToKeep, [ 'declarantpersonnenom', - 'declarantservice', 'declarantpersonneportable', 'declarantpersonneemail', 'declarantpersonnefix' ]); + + if ($initialisationRecu === false) { + $fieldsToKeep = array_merge ($fieldsToKeep, [ + 'declarantservice', + ]); + } } $data = $this->cleanupData($data, $champs, $formulaireOLD, $fieldsToKeep); diff --git a/app/View/Elements/Fiches/tabs/informationGenerale.ctp b/app/View/Elements/Fiches/tabs/informationGenerale.ctp index 96c016dc71c09e29e5c81cecc01cb4bf4187066d..b614b312cade04cdc2cc4d885242a345c9c76cdc 100644 --- a/app/View/Elements/Fiches/tabs/informationGenerale.ctp +++ b/app/View/Elements/Fiches/tabs/informationGenerale.ctp @@ -1,10 +1,18 @@ request->params['action'], ['edit', 'show']) === true) { $empty = false; $keySubmit = 'Trash.'; + + if ($initialisationRecu === true) { + $keySubmitService = 'WebdpoFiche.'; + } else { + $keySubmitService = 'Trash.'; + } } if (!isset($fieldsIsRequired)){ @@ -38,46 +46,49 @@ if (!isset($fieldsIsRequired)){ 'required' => true ]); - $countService = count($this->Session->read('User.service')); - - // Champ Service * - if ($countService >= 2 && $fieldsIsRequired === true) { - foreach ($this->Session->read('User.service') as $service) { - $listeUserService[$service] = $service; - } - - echo $this->WebcilForm->input($keySubmit.'declarantservice', [ - 'id' => 'declarantservice', - 'label' => [ - 'text' => __d('fiche', 'fiche.champDeclarantservice') - ], - 'options' => $listeUserService, - 'empty' => __d('fiche', 'fiche.emptySelectionnerServiceDeclarant'), - 'required' => true, - 'placeholder' => false - ]); - } else if ($countService == 0 || $fieldsIsRequired === false) { - echo $this->WebcilForm->input($keySubmit.'declarantservice', [ - 'id' => 'declarantservice', - 'label' => [ - 'text' => __d('fiche', 'fiche.champDeclarantservice') - ], - 'readonly' => true, - 'required' => true, - 'value' => 'Aucun service' - ]); + $serviceFieldOptions = [ + 'id' => 'declarantservice', + 'label' => [ + 'text' => __d('fiche', 'fiche.champDeclarantservice') + ], + 'required' => true, + ]; + + if (in_array($this->request->params['action'], ['edit', 'show']) !== true || + $initialisationRecu === true + ) { + $countService = count($this->Session->read('User.service')); + + if ($countService >= 2 && $fieldsIsRequired === true) { + foreach ($this->Session->read('User.service') as $service) { + $listeUserService[$service] = $service; + } + + $serviceFieldOptions += [ + 'options' => $listeUserService, + 'empty' => __d('fiche', 'fiche.emptySelectionnerServiceDeclarant'), + 'placeholder' => false + ]; + } else + if ($countService == 0 || $fieldsIsRequired === false) { + $serviceFieldOptions += [ + 'readonly' => true, + 'value' => 'Aucun service' + ]; + } else { + $serviceFieldOptions += [ + 'readonly' => true, + 'value' => $this->Session->read('User.service') + ]; + } } else { - echo $this->WebcilForm->input($keySubmit.'declarantservice', [ - 'id' => 'declarantservice', - 'label' => [ - 'text' => __d('fiche', 'fiche.champDeclarantservice') - ], - 'readonly' => true, - 'required' => true, - 'value' => $this->Session->read('User.service') - ]); + $serviceFieldOptions += [ + 'readonly' => true + ]; } + echo $this->WebcilForm->input($keySubmitService.'declarantservice', $serviceFieldOptions); + echo $this->WebcilForm->input($keySubmit.'declarantpersonneportable', [ 'id' => 'declarantpersonneportable', 'label' => [