From 93022a406c7a5292a63d8d8efb6ea1b487e97a6c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Mar 2023 15:25:12 +0100 Subject: [PATCH] NEW Keep a link between user created from recruitment and application --- .../install/mysql/migration/17.0.0-18.0.0.sql | 3 + ...ent_recruitmentcandidature-recruitment.sql | 1 + .../class/recruitmentcandidature.class.php | 2 + .../recruitmentcandidature_card.php | 67 ++++++++++--------- 4 files changed, 43 insertions(+), 30 deletions(-) diff --git a/htdocs/install/mysql/migration/17.0.0-18.0.0.sql b/htdocs/install/mysql/migration/17.0.0-18.0.0.sql index 718863849a6..f12fd564831 100644 --- a/htdocs/install/mysql/migration/17.0.0-18.0.0.sql +++ b/htdocs/install/mysql/migration/17.0.0-18.0.0.sql @@ -93,3 +93,6 @@ ALTER TABLE llx_ecm_files ADD COLUMN share_pass varchar(32) after share; ALTER TABLE llx_prelevement_demande ADD COLUMN type varchar(12) DEFAULT ''; UPDATE llx_prelevement_demande SET type = 'ban' WHERE ext_payment_id IS NULL AND type = ''; + +ALTER TABLE llx_recruitment_recruitmentcandidature ADD COLUMN fk_user integer; + diff --git a/htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature-recruitment.sql b/htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature-recruitment.sql index 8d5dd3bd14f..676d5ade157 100644 --- a/htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature-recruitment.sql +++ b/htdocs/install/mysql/tables/llx_recruitment_recruitmentcandidature-recruitment.sql @@ -27,6 +27,7 @@ CREATE TABLE llx_recruitment_recruitmentcandidature( tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, fk_user_creat integer NOT NULL, fk_user_modif integer, + fk_user integer, -- Id of user created from the job application import_key varchar(14), model_pdf varchar(255), status smallint NOT NULL, diff --git a/htdocs/recruitment/class/recruitmentcandidature.class.php b/htdocs/recruitment/class/recruitmentcandidature.class.php index 809b8d0cd54..6dae3e08388 100644 --- a/htdocs/recruitment/class/recruitmentcandidature.class.php +++ b/htdocs/recruitment/class/recruitmentcandidature.class.php @@ -129,6 +129,7 @@ class RecruitmentCandidature extends CommonObject 'description' => array('type'=>'html', 'label'=>'Description', 'enabled'=>'1', 'position'=>300, 'notnull'=>0, 'visible'=>3, 'cssview'=>'wordbreak'), 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>'1', 'position'=>500, 'notnull'=>1, 'visible'=>-4, 'csslist'=>'nowraponall'), 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>501, 'notnull'=>0, 'visible'=>-2, 'csslist'=>'nowraponall'), + 'fk_user' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'LinkedToDolibarrUser', 'enabled'=>'1', 'position'=>600, 'notnull'=>0, 'visible'=>-1, 'csslist'=>'tdoverflowmax100'), 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>'1', 'position'=>1000, 'notnull'=>-1, 'visible'=>-2,), 'model_pdf' => array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>'1', 'position'=>1010, 'notnull'=>-1, 'visible'=>0,), 'status' => array('type'=>'smallint', 'label'=>'Status', 'enabled'=>'1', 'position'=>1000, 'notnull'=>1, 'visible'=>1, 'index'=>1, 'default'=>0, 'arrayofkeyval'=>array('0'=>'Draft', '1'=>'Received', '3'=>'ContractProposed', '5'=>'ContractSigned', '8'=>'Refused', '9'=>'Canceled')), @@ -144,6 +145,7 @@ class RecruitmentCandidature extends CommonObject public $tms; public $fk_user_creat; public $fk_user_modif; + public $fk_user; public $lastname; public $firstname; public $email; diff --git a/htdocs/recruitment/recruitmentcandidature_card.php b/htdocs/recruitment/recruitmentcandidature_card.php index 62f7ed5cc9b..50594489d8b 100644 --- a/htdocs/recruitment/recruitmentcandidature_card.php +++ b/htdocs/recruitment/recruitmentcandidature_card.php @@ -202,38 +202,46 @@ if (empty($reshook)) { // Create user from a member if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer) { - if ($result > 0) { - $jobposition = new RecruitmentJobPosition($db); - $jobposition->fetch($object->fk_recruitmentjobposition); + $jobposition = new RecruitmentJobPosition($db); + $jobposition->fetch($object->fk_recruitmentjobposition); - // Creation user - $nuser = new User($db); - $nuser->login = GETPOST('login', 'alphanohtml'); - $nuser->fk_soc = 0; - $nuser->employee = 1; - $nuser->firstname = $object->firstname; - $nuser->lastname = $object->lastname; - $nuser->email = ''; - $nuser->personal_email = $object->email; - $nuser->personal_mobile = $object->phone; - $nuser->birth = $object->date_birth; - $nuser->salary = $object->remuneration_proposed; - $nuser->fk_user = $jobposition->fk_user_supervisor; // Supervisor - $nuser->email = $object->email; + $db->begin(); - $result = $nuser->create($user); + // Creation user + $nuser = new User($db); + $nuser->login = GETPOST('login', 'alphanohtml'); + $nuser->fk_soc = 0; + $nuser->employee = 1; + $nuser->firstname = $object->firstname; + $nuser->lastname = $object->lastname; + $nuser->email = ''; + $nuser->personal_email = $object->email; + $nuser->personal_mobile = $object->phone; + $nuser->birth = $object->date_birth; + $nuser->salary = $object->remuneration_proposed; + $nuser->fk_user = $jobposition->fk_user_supervisor; // Supervisor + $nuser->email = $object->email; - if ($result < 0) { - $langs->load("errors"); - setEventMessages($langs->trans($nuser->error), null, 'errors'); - $action = 'create_user'; - } else { - setEventMessages($langs->trans("NewUserCreated", $nuser->login), null, 'mesgs'); - $action = ''; - } - } else { - setEventMessages($object->error, $object->errors, 'errors'); + $result = $nuser->create($user); + + if ($result < 0) { + $error++; + $langs->load("errors"); + setEventMessages($langs->trans($nuser->error), null, 'errors'); $action = 'create_user'; + } else { + $object->fk_user = $result; + + $object->update($user); + } + + if (!$error) { + $db->commit(); + + setEventMessages($langs->trans("NewUserCreated", $nuser->login), null, 'mesgs'); + $action = ''; + } else { + $db->rollback(); } } @@ -572,8 +580,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea // Button to convert into a user if ($object->status == $object::STATUS_CONTRACT_SIGNED) { if ($user->rights->user->user->creer) { - // TODO Check if a user already exists - $useralreadyexists = 0; + $useralreadyexists = $object->fk_user; if (empty($useralreadyexists)) { print '
'.$langs->trans("CreateDolibarrLogin").'
'; } else {