diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 83b9b1e55a8ef..d2a4cc606aa73 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -6,7 +6,7 @@ * Copyright (C) 2020 Juanjo Menent * Copyright (C) 2022 Charlene Benke * Copyright (C) 2023 Gauthier VERDOL - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1417,9 +1417,9 @@ public function mergeTimeSpentTask($origin_id, $dest_id) /** * Add time spent * - * @param User $user User object - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int Return integer <=0 if KO, >0 if OK + * @param User $user User object + * @param int<0,1> $notrigger 0=launch triggers after, 1=disable triggers + * @return int Return integer <=0 if KO, >0 if OK */ public function addTimeSpent($user, $notrigger = 0) { diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 4f7541724fc46..6afdc5bc7c323 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -7,7 +7,7 @@ * Copyright (C) 2018 Frédéric France * Copyright (C) 2019-2021 Christophe Battarel * Copyright (C) 2023 Gauthier VERDOL - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Vincent de Grandpré * Copyright (C) 2024 Solution Libre SAS * @@ -270,6 +270,7 @@ if (($action == 'updateline' || $action == 'updatesplitline') && !$cancel && $user->hasRight('projet', 'lire')) { $error = 0; + $db->begin(); if (!GETPOST("new_durationhour") && !GETPOST("new_durationmin")) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Duration")), null, 'errors'); @@ -300,10 +301,21 @@ } else { $object->timespent_date = dol_mktime(12, 0, 0, GETPOST("timelinemonth"), GETPOST("timelineday"), GETPOST("timelineyear")); } - $object->timespent_fk_user = GETPOSTINT("userid_line"); - $object->timespent_fk_product = GETPOSTINT("fk_product"); - $object->timespent_invoiceid = GETPOSTINT("invoiceid"); - $object->timespent_invoicelineid = GETPOSTINT("invoicelineid"); + + // Use fields from existing record or from post (if provided) + if (GETPOST("userid_line") != '') { + $object->timespent_fk_user = GETPOSTINT("userid_line"); + } + if (GETPOST("fk_product") != '') { + $object->timespent_fk_product = GETPOSTINT("fk_product"); + } + if (GETPOST("invoiceid") != '') { + $object->timespent_invoiceid = GETPOSTINT("invoiceid"); + } + if (GETPOST("invoicelineid") != '') { + $object->timespent_invoicelineid = GETPOSTINT("invoicelineid"); + } + $result = 0; if (in_array($object->timespent_fk_user, $childids) || $user->hasRight('projet', 'all', 'creer')) { @@ -349,6 +361,11 @@ } else { $action = ''; } + if ($error == 0) { + $db->commit(); + } else { + $db->rollback(); + } } if ($action == 'confirm_deleteline' && $confirm == "yes" && ($user->hasRight('projet', 'time') || $user->hasRight('projet', 'all', 'creer'))) {