Skip to content

Commit

Permalink
[TrainingSession] fix: duration field
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-theo committed Aug 26, 2022
1 parent f32ea59 commit 10a2948
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
39 changes: 21 additions & 18 deletions core/tpl/session/dolimeet_session_card.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,14 @@
$society_id = GETPOST('fk_soc');
$project_id = GETPOST('projectid');
$contrat_id = GETPOST('fk_contrat');
$duration = GETPOST('duration');
$durationh = GETPOST('durationh') ?:0;
$durationm = GETPOST('durationm') ?: 0;

$duration_minutes = $durationh * 60 + $durationm;

$date_start = dol_mktime(GETPOST('date_starthour', 'int'), GETPOST('date_startmin', 'int'), 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int'));
$date_end = dol_mktime(GETPOST('date_endhour', 'int'), GETPOST('date_endmin', 'int'), 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'));

$minutes = 0;
if (preg_match('/,/', $duration)){
$hours = preg_split('/,/', $duration)[0];
$minutes = ($duration - $hours) * 60;
} else if (preg_match('/./', $duration)){
$hours = preg_split('/\./', $duration)[0];
$minutes = ($duration - $hours) * 60;
}
$duration_minutes = $hours * 60 + $minutes;

// Initialize object
$now = dol_now();
$object->ref = $refMod->getNextValue($object);
Expand Down Expand Up @@ -195,6 +189,10 @@
$project_id = GETPOST('fk_project');
$date_start = dol_mktime(GETPOST('date_starthour', 'int'), GETPOST('date_startmin', 'int'), 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int'));
$date_end = dol_mktime(GETPOST('date_endhour', 'int'), GETPOST('date_endmin', 'int'), 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int'));
$durationh = GETPOST('durationh') ?:0;
$durationm = GETPOST('durationm') ?: 0;

$duration_minutes = $durationh * 60 + $durationm;

$object->label = $label;
$object->fk_soc = $society_id;
Expand All @@ -203,6 +201,7 @@
$object->fk_project = $project_id;
$object->date_start = $date_start;
$object->date_end = $date_end;
$object->duration = $duration_minutes;

$object->fk_user_creat = $user->id ? $user->id : 1;
if (!$error) {
Expand Down Expand Up @@ -758,9 +757,12 @@
print ' <a href="' . DOL_URL_ROOT . '/contrat/card.php?&action=create&status=1&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create') . '"><span class="fa fa-plus-circle valignmiddle" title="' . $langs->trans("AddContract") . '"></span></a>';
print '</td></tr>';

//Date end - Date de début
print '<tr class="oddeven"><td><label for="Duration">' . $langs->trans("DurationH") . '</label></td><td>';
print '<input type=number step=".01" name="duration" id="duration" value="'. GETPOST('duration') .'">';
//Duration - Durée
print '<tr class="oddeven"><td><label for="Duration">' . $langs->trans("Duration") . '</label></td><td>';
print '<input type=number name="durationh" id="durationh" value="'. GETPOST('durationh') .'">';
print $langs->trans('Hour(s)');
print '<input type=number name="durationm" id="durationm" value="'. GETPOST('durationm') .'">';
print $langs->trans('Minute(s)');
print '</td></tr>';
}

Expand Down Expand Up @@ -884,8 +886,9 @@
//Duration - Durée
print '<tr class="oddeven"><td><label for="Duration">' . $langs->trans("DurationH") . '</label></td><td>';
$duration_hours = floor($object->duration / 60);
$duration_minutes = ($object->duration % 60) * 100/60;
print '<input type=number step=".01" name="duration" id="duration" value="'. $duration_hours . '.' . $duration_minutes .'">';
$duration_minutes = ($object->duration % 60);
print '<input type=number name="durationh" id="durationh" value="'. $duration_hours .'">';
print '<input type=number name="durationm" id="durationm" value="'. $duration_minutes .'">';
print '</td></tr>';
}

Expand Down Expand Up @@ -1045,13 +1048,13 @@

if ($object->type == 'trainingsession') {
$duration_hours = floor($object->duration / 60);
$duration_minutes = ($object->duration % 60) * 100/60;
$duration_minutes = ($object->duration % 60);

print '<tr><td class="titlefield">';
print $langs->trans("Duration");
print '</td>';
print '<td>';
print $duration_hours . '.' . $duration_minutes . ' ' . $langs->trans('Hours');
print $duration_hours . ' ' . $langs->trans('Hour(s)') . ' ' . $duration_minutes . ' ' . $langs->trans('Minute(s)');
print '</td></tr>';
}

Expand Down
2 changes: 2 additions & 0 deletions langs/fr_FR/dolimeet.lang
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ ModuleConfiguration = Configuration du module
DoliMeetSettings = Réglages de DoliMeet
DoliMeetObjects = Objets de DoliMeet
LinkedDocuments = Documents liés
Hour(s) = Heure(s)
Minute(s) = Minute(s)

#
# Session
Expand Down

0 comments on commit 10a2948

Please sign in to comment.