NEW Keep a link between user created from recruitment and application

This commit is contained in:
Laurent Destailleur 2023-03-02 15:25:12 +01:00
parent f3a3a8b854
commit 93022a406c
4 changed files with 43 additions and 30 deletions

View File

@ -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 ''; 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 = ''; 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;

View File

@ -27,6 +27,7 @@ CREATE TABLE llx_recruitment_recruitmentcandidature(
tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, tms timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
fk_user_creat integer NOT NULL, fk_user_creat integer NOT NULL,
fk_user_modif integer, fk_user_modif integer,
fk_user integer, -- Id of user created from the job application
import_key varchar(14), import_key varchar(14),
model_pdf varchar(255), model_pdf varchar(255),
status smallint NOT NULL, status smallint NOT NULL,

View File

@ -129,6 +129,7 @@ class RecruitmentCandidature extends CommonObject
'description' => array('type'=>'html', 'label'=>'Description', 'enabled'=>'1', 'position'=>300, 'notnull'=>0, 'visible'=>3, 'cssview'=>'wordbreak'), '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'), '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'), '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,), '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,), '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')), '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 $tms;
public $fk_user_creat; public $fk_user_creat;
public $fk_user_modif; public $fk_user_modif;
public $fk_user;
public $lastname; public $lastname;
public $firstname; public $firstname;
public $email; public $email;

View File

@ -202,10 +202,11 @@ if (empty($reshook)) {
// Create user from a member // Create user from a member
if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer) { if ($action == 'confirm_create_user' && $confirm == 'yes' && $user->rights->user->user->creer) {
if ($result > 0) {
$jobposition = new RecruitmentJobPosition($db); $jobposition = new RecruitmentJobPosition($db);
$jobposition->fetch($object->fk_recruitmentjobposition); $jobposition->fetch($object->fk_recruitmentjobposition);
$db->begin();
// Creation user // Creation user
$nuser = new User($db); $nuser = new User($db);
$nuser->login = GETPOST('login', 'alphanohtml'); $nuser->login = GETPOST('login', 'alphanohtml');
@ -224,16 +225,23 @@ if (empty($reshook)) {
$result = $nuser->create($user); $result = $nuser->create($user);
if ($result < 0) { if ($result < 0) {
$error++;
$langs->load("errors"); $langs->load("errors");
setEventMessages($langs->trans($nuser->error), null, 'errors'); setEventMessages($langs->trans($nuser->error), null, 'errors');
$action = 'create_user'; $action = 'create_user';
} else { } else {
$object->fk_user = $result;
$object->update($user);
}
if (!$error) {
$db->commit();
setEventMessages($langs->trans("NewUserCreated", $nuser->login), null, 'mesgs'); setEventMessages($langs->trans("NewUserCreated", $nuser->login), null, 'mesgs');
$action = ''; $action = '';
}
} else { } else {
setEventMessages($object->error, $object->errors, 'errors'); $db->rollback();
$action = 'create_user';
} }
} }
@ -572,8 +580,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
// Button to convert into a user // Button to convert into a user
if ($object->status == $object::STATUS_CONTRACT_SIGNED) { if ($object->status == $object::STATUS_CONTRACT_SIGNED) {
if ($user->rights->user->user->creer) { if ($user->rights->user->user->creer) {
// TODO Check if a user already exists $useralreadyexists = $object->fk_user;
$useralreadyexists = 0;
if (empty($useralreadyexists)) { if (empty($useralreadyexists)) {
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=create_user">'.$langs->trans("CreateDolibarrLogin").'</a></div>'; print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=create_user">'.$langs->trans("CreateDolibarrLogin").'</a></div>';
} else { } else {