diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index b29f001bda2..54779bb692d 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -143,7 +143,16 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once if ($action == 'confirm_active' && $confirm == 'yes' && $user->rights->contrat->activer) { - $result = $object->active_line($user, GETPOST('ligne', 'int'), GETPOST('date'), GETPOST('dateend'), GETPOST('comment')); + $date_start = ''; + $date_end = ''; + if (GETPOST('startmonth') && GETPOST('startday') && GETPOST('startyear')) { + $date_start = dol_mktime(GETPOST('starthour'), GETPOST('startmin'), 0, GETPOST('startmonth'), GETPOST('startday'), GETPOST('startyear')); + } + if (GETPOST('endmonth') && GETPOST('endday') && GETPOST('endyear')) { + $date_end = dol_mktime(GETPOST('endhour'), GETPOST('endmin'), 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); + } + + $result = $object->active_line($user, GETPOST('ligne', 'int'), $date_start, $date_end, GETPOST('comment')); if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); @@ -152,12 +161,16 @@ if (empty($reshook)) { setEventMessages($object->error, $object->errors, 'errors'); } } elseif ($action == 'confirm_closeline' && $confirm == 'yes' && $user->rights->contrat->activer) { - if (!GETPOST('dateend')) { + $date_end = ''; + if (GETPOST('endmonth') && GETPOST('endday') && GETPOST('endyear')) { + $date_end = dol_mktime(GETPOST('endhour'), GETPOST('endmin'), 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); + } + if (!$date_end) { $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), null, 'errors'); } if (!$error) { - $result = $object->close_line($user, GETPOST('ligne', 'int'), GETPOST('dateend'), urldecode(GETPOST('comment'))); + $result = $object->close_line($user, GETPOST('ligne', 'int'), $date_end, urldecode(GETPOST('comment'))); if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; @@ -1838,34 +1851,6 @@ if ($action == 'create') { print '
'; } - /* - * Confirmation de la validation activation - */ - if ($action == 'active' && !$cancel && $user->rights->contrat->activer && $object->lines[$cursorline - 1]->id == GETPOST('ligne', 'int')) { - $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); - $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); - $comment = GETPOST('comment', 'alpha'); - print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".GETPOST('ligne', 'int')."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment), $langs->trans("ActivateService"), $langs->trans("ConfirmActivateService", dol_print_date($dateactstart, "%A %d %B %Y")), "confirm_active", '', 0, 1); - print '
'; - } - - /* - * Confirmation de la validation fermeture - */ - if ($action == 'closeline' && !$cancel && $user->rights->contrat->activer && $object->lines[$cursorline - 1]->id == GETPOST('ligne', 'int')) { - $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); - $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); - $comment = GETPOST('comment', 'alpha'); - - if (empty($dateactend)) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEndReal")), null, 'errors'); - } else { - print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".GETPOST('ligne', 'int')."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment), $langs->trans("CloseService"), $langs->trans("ConfirmCloseService", dol_print_date($dateactend, "%A %d %B %Y")), "confirm_closeline", '', 0, 1); - } - print '
'; - } - - // Area with status and activation info of line if ($object->statut > 0) { print ''; @@ -1931,8 +1916,12 @@ if ($action == 'create') { // Form to activate line if ($user->rights->contrat->activer && $action == 'activateline' && $object->lines[$cursorline - 1]->id == GETPOST('ligne', 'int')) { - print ''; + print ''; print ''; + print ''; + print ''; + print ''; + print ''; print '
'; @@ -1957,7 +1946,7 @@ if ($action == 'create') { print ''; print ''; print '
'.$langs->trans("DateServiceActivate").''; - print $form->selectDate($dateactstart, '', $usehm, $usehm, '', "active", 1, 0); + print $form->selectDate($dateactstart, 'start', $usehm, $usehm, '', "active", 1, 0); print ''.$langs->trans("DateEndPlanned").''; print $form->selectDate($dateactend, "end", $usehm, $usehm, '', "active", 1, 0); @@ -1985,10 +1974,10 @@ if ($action == 'create') { * Disable a contract line */ print ''."\n"; - print ''; - + print ''; print ''; - print ''; + print ''; + print ''; print ''; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index bf945eeae96..0357459052b 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -321,15 +321,15 @@ class Contrat extends CommonObject * * @param User $user Objet User who activate contract * @param int $line_id Id of line to activate - * @param int $date Opening date + * @param int $date_start Opening date * @param int|string $date_end Expected end date * @param string $comment A comment typed by user * @return int <0 if KO, >0 if OK */ - public function active_line($user, $line_id, $date, $date_end = '', $comment = '') + public function active_line($user, $line_id, $date_start, $date_end = '', $comment = '') { // phpcs:enable - $result = $this->lines[$this->lines_id_index_mapper[$line_id]]->active_line($user, $date, $date_end, $comment); + $result = $this->lines[$this->lines_id_index_mapper[$line_id]]->active_line($user, $date_start, $date_end, $comment); if ($result < 0) { $this->error = $this->lines[$this->lines_id_index_mapper[$line_id]]->error; $this->errors = $this->lines[$this->lines_id_index_mapper[$line_id]]->errors; @@ -3588,7 +3588,7 @@ class ContratLigne extends CommonObjectLine * Activate a contract line * * @param User $user Objet User who activate contract - * @param int $date Date activation + * @param int $date Date real activation * @param int|string $date_end Date planned end. Use '-1' to keep it unchanged. * @param string $comment A comment typed by user * @return int <0 if KO, >0 if OK @@ -3603,13 +3603,13 @@ class ContratLigne extends CommonObjectLine $this->db->begin(); $this->statut = ContratLigne::STATUS_OPEN; - $this->date_start = $date; + $this->date_start_real = $date; $this->date_end = $date_end; $this->fk_user_ouverture = $user->id; $this->date_end_real = null; $this->commentaire = $comment; - $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET statut = ".$this->statut.","; + $sql = "UPDATE ".MAIN_DB_PREFIX."contratdet SET statut = ".((int) $this->statut).","; $sql .= " date_ouverture = ".(dol_strlen($this->date_start_real) != 0 ? "'".$this->db->idate($this->date_start_real)."'" : "null").","; if ($date_end >= 0) { $sql .= " date_fin_validite = ".(dol_strlen($this->date_end) != 0 ? "'".$this->db->idate($this->date_end)."'" : "null").","; @@ -3648,7 +3648,7 @@ class ContratLigne extends CommonObjectLine * Close a contract line * * @param User $user Objet User who close contract - * @param int $date_end_real Date end + * @param int $date_end_real Date end * @param string $comment A comment typed by user * @param int $notrigger 1=Does not execute triggers, 0=Execute triggers * @return int <0 if KO, >0 if OK