Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#651 [Hook] add: rework generate document contract #652

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions admin/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@
dolibarr_set_const($db, 'DOLIMEET_TRAININGSESSION_LOCATION', $trainingSessionLocation, 'chaine', 0, '', $conf->entity);
}

$trainingSessionAbsenceRate = GETPOST('training_session_absence_rate', 'int');
if ($trainingSessionAbsenceRate != getDolGlobalInt('DOLIMEET_TRAININGSESSION_ABSENCE_RATE')) {
dolibarr_set_const($db, 'DOLIMEET_TRAININGSESSION_ABSENCE_RATE', $trainingSessionAbsenceRate, 'integer', 0, '', $conf->entity);
}

setEventMessage('SavedConfig');
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
Expand Down Expand Up @@ -246,6 +251,12 @@
print '<input type="radio" id="TrainingSessionLocationOther" name="training_session_location" value="TrainingSessionLocationOther"' . (getDolGlobalString('DOLIMEET_TRAININGSESSION_LOCATION') == 'TrainingSessionLocationOther' ? 'checked' : '') . '/><label for="TrainingSessionLocationOther">' . img_picto('', 'fontawesome_fa-font_fas', 'class="paddingright"') . $langs->transnoentities('TrainingSessionLocationOther') . '</label>';
print '</td></tr>';

// Training session absence rate
print '<tr class="oddeven"><td>' . $langs->transnoentities('TrainingSessionAbsenceRate') . '</td><td>';
print img_picto('', 'sort-numeric-down', 'class="pictofixedwidth"');
print '<input type="number" name="training_session_absence_rate" min="0" max="100" value="' . getDolGlobalInt('DOLIMEET_TRAININGSESSION_ABSENCE_RATE') . '"/>';
print '</td></tr>';

print '</table>';
print '<div class="tabsAction"><input type="submit" class="butAction" name="save" value="' . $langs->trans('Save') . '"></div>';
print '</form>';
Expand Down
279 changes: 102 additions & 177 deletions class/actions_dolimeet.class.php

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions class/session.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ class Session extends SaturneObject
'import_key' => ['type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 60, 'notnull' => 0, 'visible' => 0, 'index' => 0],
'status' => ['type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 190, 'notnull' => 1, 'visible' => 2, 'default' => 0, 'index' => 1, 'validate' => 1, 'arrayofkeyval' => [0 => 'StatusDraft', 1 => 'ValidatePendingSignature', 2 => 'Locked', 3 => 'Archived']],
'label' => ['type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 70, 'notnull' => 1, 'visible' => 1, 'searchall' => 1, 'css' => 'minwidth300', 'cssview' => 'wordbreak', 'showoncombobox' => 2, 'validate' => 1, 'autofocusoncreate' => 1],
'date_start' => ['type' => 'datetime', 'label' => 'DateStart', 'enabled' => 1, 'position' => 110, 'notnull' => 0, 'visible' => 1],
'date_end' => ['type' => 'datetime', 'label' => 'DateEnd', 'enabled' => 1, 'position' => 120, 'notnull' => 0, 'visible' => 1],
'date_start' => ['type' => 'datetime', 'label' => 'DateStart', 'enabled' => 1, 'position' => 41, 'notnull' => 0, 'visible' => 1],
'date_end' => ['type' => 'datetime', 'label' => 'DateEnd', 'enabled' => 1, 'position' => 42, 'notnull' => 0, 'visible' => 1],
'content' => ['type' => 'html', 'label' => 'Content', 'enabled' => 1, 'position' => 140, 'notnull' => 0, 'visible' => 3, 'validate' => 1],
'type' => ['type' => 'varchar(128)', 'label' => 'Type', 'enabled' => 1, 'position' => 120, 'notnull' => 1, 'visible' => 0],
'element_type' => ['type' => 'select', 'label' => 'ElementType', 'enabled' => 1, 'position' => 91, 'notnull' => 0, 'visible' => 3, 'css' => 'maxwidth150 widthcentpercentminusxx'],
Expand Down
27 changes: 21 additions & 6 deletions core/modules/modDoliMeet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ public function __construct($db)
$i++ => ['DOLIMEET_TRAININGSESSION_AFTERNOON_START_HOUR', 'chaine', '14:00', '', 0, 'current'],
$i++ => ['DOLIMEET_TRAININGSESSION_AFTERNOON_END_HOUR', 'chaine', '18:00', '', 0, 'current'],
$i++ => ['DOLIMEET_TRAININGSESSION_LOCATION', 'chaine', 'TrainingSessionLocationOther', '', 0, 'current'],
$i++ => ['DOLIMEET_TRAININGSESSION_ABSENCE_RATE', 'integer', 20, '', 0, 'current'],

// CONST GENERAL CONST.
$i++ => ['CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST', 'integer', 1, '', 0, 'current'],
Expand Down Expand Up @@ -629,7 +630,9 @@ public function init($options = ''): int
$saturneMail->joinfiles = 0;
$saturneMail->content = $langs->transnoentities('CompletionCertificateDocumentContent');

dolibarr_set_const($this->db, 'DOLIMEET_EMAIL_TEMPLATE_COMPLETION_CERTIFICATE', $saturneMail->create($user), 'chaine', 0, '', $conf->entity);
$emailTemplateID = $saturneMail->create($user);

dolibarr_set_const($this->db, 'DOLIMEET_EMAIL_TEMPLATE_COMPLETION_CERTIFICATE', $emailTemplateID, 'chaine', 0, '', $conf->entity);
dolibarr_set_const($this->db, 'DOLIMEET_EMAIL_TEMPLATE_SET', 2, 'integer', 0, '', $conf->entity);
}

Expand Down Expand Up @@ -673,17 +676,29 @@ public function init($options = ''): int
'trainingsession_type' => ['Label' => 'TrainingSessionType', 'type' => 'sellist', 'length' => '', 'elementtype' => ['contrat', 'propal', 'projet'], 'position' => 10, 'params' => 'a:1:{s:7:"options";a:1:{s:34:"c_trainingsession_type:label:rowid";N;}}', 'list' => 1, 'help' => ['contrat' => '', 'propal' => '', 'projet' => 'TrainingSessionTypeHelp'], 'entity' => 0, 'langfile' => 'dolimeet@dolimeet', 'enabled' => "isModEnabled('dolimeet')", ['css' => 'minwidth100 maxwidth300 widthcentpercentminusxx']],
'trainingsession_service' => ['Label' => 'TrainingSessionService', 'type' => 'chkbxlst', 'length' => '', 'elementtype' => ['propal', 'projet'], 'position' => 10, 'params' => '', 'list' => 1, 'help' => 'TrainingSessionServiceHelp', 'entity' => 0, 'langfile' => 'dolimeet@dolimeet', 'enabled' => "isModEnabled('dolimeet')", ['css' => 'minwidth100 maxwidth300 widthcentpercentminusxx']],
'trainingsession_location' => ['Label' => 'TrainingSessionLocation', 'type' => 'varchar', 'length' => 255, 'elementtype' => ['contrat', 'propal', 'projet'], 'position' => 20, 'params' => '', 'list' => 1, 'help' => 'TrainingSessionLocationHelp', 'entity' => 0, 'langfile' => 'dolimeet@dolimeet', 'enabled' => "isModEnabled('dolimeet')", ['css' => 'minwidth100 maxwidth300 widthcentpercentminusxx']],
'trainingsession_start' => ['Label' => 'TrainingSessionStart', 'type' => 'datetime', 'length' => '', 'elementtype' => ['contrat'], 'position' => 30, 'params' => '', 'list' => 1, 'help' => 'TrainingSessionStartHelp', 'entity' => 0, 'langfile' => 'dolimeet@dolimeet', 'enabled' => "isModEnabled('dolimeet')"],
'trainingsession_end' => ['Label' => 'TrainingSessionEnd', 'type' => 'datetime', 'length' => '', 'elementtype' => ['contrat'], 'position' => 40, 'params' => '', 'list' => 1, 'help' => 'TrainingSessionEndHelp', 'entity' => 0, 'langfile' => 'dolimeet@dolimeet', 'enabled' => "isModEnabled('dolimeet')"],
'trainingsession_durations' => ['Label' => 'TrainingSessionDurations', 'type' => 'int', 'length' => '', 'elementtype' => ['contrat'], 'position' => 50, 'params' => '', 'list' => 5, 'help' => 'TrainingSessionDurationHelp', 'entity' => 0, 'langfile' => 'dolimeet@dolimeet', 'enabled' => "isModEnabled('dolimeet')"],
'trainingsession_opco_financing' => ['Label' => 'TrainingSessionOpcoFinancing', 'type' => 'boolean', 'length' => '', 'elementtype' => ['contrat'], 'position' => 60, 'params' => '', 'list' => 5, 'help' => 'TrainingSessionOpcoFinancingHelp', 'entity' => 0, 'langfile' => 'dolimeet@dolimeet', 'enabled' => "isModEnabled('dolimeet')"]
'trainingsession_opco_financing' => ['Label' => 'TrainingSessionOpcoFinancing', 'type' => 'boolean', 'length' => '', 'elementtype' => ['contrat'], 'position' => 60, 'params' => '', 'alwayseditable' => 1, 'list' => 5, 'help' => 'TrainingSessionOpcoFinancingHelp', 'entity' => 0, 'langfile' => 'dolimeet@dolimeet', 'enabled' => "isModEnabled('dolimeet')"]
];

foreach ($extraFieldsArrays as $key => $extraField) {
foreach ($extraField['elementtype'] as $extraFieldElementType) {
$extraFields->update($key, $extraField['Label'], $extraField['type'], $extraField['length'], $extraFieldElementType, 0, 0, $this->numero . $extraField['position'], $extraField['params'], '', '', $extraField['list'], ($extraField['help'][$extraFieldElementType] ?? $extraField['help']), '', '', $extraField['entity'], $extraField['langfile'], $extraField['enabled'] . ' && isModEnabled("' . $extraFieldElementType . '")', 0, 0, $extraField['css']);
$extraFields->addExtraField($key, $extraField['Label'], $extraField['type'], $this->numero . $extraField['position'], $extraField['length'], $extraFieldElementType, 0, 0, '', $extraField['params'], '', '', $extraField['list'], $extraField['help'], '', $extraField['entity'], $extraField['langfile'], $extraField['enabled'] . ' && isModEnabled("' . $extraFieldElementType . '")', 0, 0, $extraField['css']);
$extraFields->addExtraField($key, $extraField['Label'], $extraField['type'], $this->numero . $extraField['position'], $extraField['length'], $extraFieldElementType, 0, 0, '', $extraField['params'], $extraField['alwayseditable'], '', $extraField['list'], $extraField['help'], '', $extraField['entity'], $extraField['langfile'], $extraField['enabled'] . ' && isModEnabled("' . $extraFieldElementType . '")', 0, 0, $extraField['css']);
}
}

if (getDolGlobalInt('DOLIMEET_EXTRAFIELDS_BACKWARD_COMPATIBILITY') == 0) {
$extraFieldsArrays = [
'trainingsession_start' => ['elementtype' => ['contrat']],
'trainingsession_end' => ['elementtype' => ['contrat']],
'trainingsession_durations' => ['elementtype' => ['contrat']]
];

foreach ($extraFieldsArrays as $key => $extraField) {
foreach ($extraField['elementtype'] as $extraFieldElementType) {
$extraFields->delete($key, $extraFieldElementType);
}
}
dolibarr_set_const($this->db, 'DOLIMEET_EXTRAFIELDS_BACKWARD_COMPATIBILITY', 1, 'integer', 0, '', $conf->entity);
}

return $this->_init($sql, $options);
Expand Down
4 changes: 1 addition & 3 deletions core/substitutions/functions_dolimeet.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function dolimeet_completesubstitutionarray(array &$substitutionarray, Translate
{
global $conf, $db, $user;

if ($object->element == 'contrat') {
if ($object && $object->element == 'contrat') {
// Load Saturne libraries
require_once __DIR__ . '/../../../saturne/class/saturnesignature.class.php';
require_once __DIR__ . '/../../../saturne/lib/saturne_functions.lib.php';
Expand Down Expand Up @@ -76,8 +76,6 @@ function dolimeet_completesubstitutionarray(array &$substitutionarray, Translate
}

$substitutionarray['__DOLIMEET_CONTRACT_LABEL__'] = $object->array_options['options_label'];
$substitutionarray['__DOLIMEET_CONTRACT_TRAININGSESSION_START__'] = $object->array_options['options_trainingsession_start'];
$substitutionarray['__DOLIMEET_CONTRACT_TRAININGSESSION_END__'] = $object->array_options['options_trainingsession_end'];
$substitutionarray['__DOLIMEET_CONTRACT_TRAININGSESSION_TYPE__'] = $object->array_options['options_trainingsession_type'];
$substitutionarray['__DOLIMEET_CONTRACT_TRAININGSESSION_LOCATION__'] = $object->array_options['options_trainingsession_location'];

Expand Down
2 changes: 1 addition & 1 deletion langs/en_US/dolimeet.lang
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ TrainingSessionLocationHelp = Place where the training session linked
TrainingSessionDurationHelp = Total duration of the sessions HH:MM (ex: 60:30) <br> The duration shown on the certificate corresponds to the total number of hours of sessions attended by a trainee.
CalculatedTotalSessionDuration = Total calculated duration time:
TrainingSessionDurationErrorMatching = <strong> Error: consistency of training session duration. </strong><br> The total duration of the sessions indicated in the contract is different from the calculated duration of all the sessions linked to the contract.
NoCertificateBecauseAbsent = No certificate was generated for <b> %s %s </b> because it was absent from all sessions.
NoCertificateBecauseAbsent = No certificate was generated for <b> %s %s </b> because it was absent from at least one session.


# Attendant role
Expand Down
3 changes: 2 additions & 1 deletion langs/fr_FR/dolimeet.lang
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ AfternoonEndHour = Heure de fin d'après-midi
TrainingSessionLocationCompany = Lieu de formation (société)
TrainingSessionLocationThirdParty = Lieu de formation (tiers)
TrainingSessionLocationOther = Autre lieu de formation par défaut
TrainingSessionAbsenceRate = Taux d'absence acceptable aux sessions de formation



Expand Down Expand Up @@ -139,7 +140,7 @@ TrainingSessionStartErrorMatchingDate = <strong> Erreur : cohérence des dates d
TrainingSessionEndErrorMatchingDate = <strong> Erreur : cohérence des dates de fin de la formation. </strong><br> La date de fin de la formation du contrat n'est pas égale à la date fin de la dernière session de formation %s.
CalculatedTotalSessionDuration = Durée totale calculée :
TrainingSessionDurationErrorMatching = <strong> Erreur : cohérence de la durée des sessions de formation. </strong><br> La durée totale des sessions indiqué dans le contrat est différente de la durée calculé de l'ensemble des sessions liées au contrat.
NoCertificateBecauseAbsent = Aucun certificat n'a été généré pour <b> %s %s </b> parcequ'il a été absent à toute les sessions.
NoCertificateBecauseAbsent = Aucun certificat n'a été généré pour <b> %s %s </b> parcequ'il a été absent à au moins une session.
ErrorMissingTrainingSessionProjectInfo = Attention : information du projet de formation manquante

# Extrafields - Attributs supplémentaires
Expand Down
2 changes: 1 addition & 1 deletion view/session/session_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
// Default sort order (if not yet defined by previous GETPOST)
if (!$sortfield) {
reset($object->fields); // Reset is required to avoid key() to return null
$sortfield = 't.date_creation';
$sortfield = 't.date_start';
}
if (!$sortorder) {
$sortorder = 'DESC';
Expand Down