From 4adf45647a332297b1ea4ea5e8f24d46dba52fc6 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 1 Mar 2010 16:42:02 +0000 Subject: [PATCH] Fix: management of time spent in task card Fix: Update time spent in seconds --- htdocs/install/upgrade2.php | 251 +++++++++++++++++++++-------- htdocs/langs/en_US/install.lang | 3 + htdocs/langs/fr_FR/install.lang | 17 +- htdocs/projet/tasks/task.class.php | 67 +++++++- htdocs/projet/tasks/time.php | 59 ++++++- 5 files changed, 314 insertions(+), 83 deletions(-) diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 7d773a99dc9..60906f1403a 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -172,72 +172,77 @@ if (isset($_POST['action']) && preg_match('/upgrade/i',$_POST["action"])) // dans la 4eme colonne, le texte 'OK' si fait ou 'AlreadyDone' si rien n'est fait ou 'Error' - // Script pour V2 -> V2.1 - migrate_paiements($db,$langs,$conf); - - migrate_contracts_det($db,$langs,$conf); - - migrate_contracts_date1($db,$langs,$conf); - - migrate_contracts_date2($db,$langs,$conf); - - migrate_contracts_date3($db,$langs,$conf); - - migrate_contracts_open($db,$langs,$conf); - - migrate_modeles($db,$langs,$conf); - - migrate_price_propal($db,$langs,$conf); - - migrate_price_commande($db,$langs,$conf); - - migrate_price_commande_fournisseur($db,$langs,$conf); - - migrate_price_facture($db,$langs,$conf); - - migrate_price_contrat($db,$langs,$conf); - - migrate_paiementfourn_facturefourn($db,$langs,$conf); - - - // Script pour V2.1 -> V2.2 - migrate_paiements_orphelins_1($db,$langs,$conf); - - migrate_paiements_orphelins_2($db,$langs,$conf); - - migrate_links_transfert($db,$langs,$conf); - - migrate_delete_old_files($db,$langs,$conf); - - - // Script pour V2.2 -> V2.4 - migrate_commande_expedition($db,$langs,$conf); - - migrate_commande_livraison($db,$langs,$conf); - - migrate_detail_livraison($db,$langs,$conf); - - migrate_module_menus($db,$langs,$conf); - - - // Script pour V2.5 -> V2.6 - migrate_stocks($db,$langs,$conf); - - - // Script pour V2.6 -> V2.7 - migrate_menus($db,$langs,$conf); - - migrate_commande_deliveryaddress($db,$langs,$conf); - - migrate_restore_missing_links($db,$langs,$conf); - - migrate_directories($db,$langs,$conf,'/compta','/banque'); - - migrate_directories($db,$langs,$conf,'/societe','/mycompany'); - + $versiontoarray=explode('.',$versionto); + + $afterversionarray=explode('.','2.0.0'); + $beforeversionarray=explode('.','2.7.9'); + if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0) + { + // Script pour V2 -> V2.1 + migrate_paiements($db,$langs,$conf); + + migrate_contracts_det($db,$langs,$conf); + + migrate_contracts_date1($db,$langs,$conf); + + migrate_contracts_date2($db,$langs,$conf); + + migrate_contracts_date3($db,$langs,$conf); + + migrate_contracts_open($db,$langs,$conf); + + migrate_modeles($db,$langs,$conf); + + migrate_price_propal($db,$langs,$conf); + + migrate_price_commande($db,$langs,$conf); + + migrate_price_commande_fournisseur($db,$langs,$conf); + + migrate_price_facture($db,$langs,$conf); + + migrate_price_contrat($db,$langs,$conf); + + migrate_paiementfourn_facturefourn($db,$langs,$conf); + + + // Script pour V2.1 -> V2.2 + migrate_paiements_orphelins_1($db,$langs,$conf); + + migrate_paiements_orphelins_2($db,$langs,$conf); + + migrate_links_transfert($db,$langs,$conf); + + migrate_delete_old_files($db,$langs,$conf); + + + // Script pour V2.2 -> V2.4 + migrate_commande_expedition($db,$langs,$conf); + + migrate_commande_livraison($db,$langs,$conf); + + migrate_detail_livraison($db,$langs,$conf); + + migrate_module_menus($db,$langs,$conf); + + + // Script pour V2.5 -> V2.6 + migrate_stocks($db,$langs,$conf); + + + // Script pour V2.6 -> V2.7 + migrate_menus($db,$langs,$conf); + + migrate_commande_deliveryaddress($db,$langs,$conf); + + migrate_restore_missing_links($db,$langs,$conf); + + migrate_directories($db,$langs,$conf,'/compta','/banque'); + + migrate_directories($db,$langs,$conf,'/societe','/mycompany'); + } // Script for -> V2.8 - $versiontoarray=explode('.',$versionto); $afterversionarray=explode('.','2.7.9'); $beforeversionarray=explode('.','2.8.9'); //print $versionto.' '.versioncompare($versiontoarray,$afterversionarray).' '.versioncompare($versiontoarray,$beforeversionarray); @@ -261,6 +266,14 @@ if (isset($_POST['action']) && preg_match('/upgrade/i',$_POST["action"])) migrate_project_task_actors($db,$langs,$conf); } + + // Script for -> V2.9 + $afterversionarray=explode('.','2.8.9'); + $beforeversionarray=explode('.','2.9.9'); + if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0) + { + migrate_project_task_time($db,$langs,$conf); + } // On commit dans tous les cas. // La procedure etant concue pour pouvoir passer plusieurs fois quelquesoit la situation. @@ -2704,6 +2717,116 @@ function migrate_relationship_tables($db,$langs,$conf,$table,$fk_source,$sourcet print ''; } +/* + * Migrate duration in seconds + */ +function migrate_project_task_time($db,$langs,$conf) +{ + dolibarr_install_syslog("upgrade2::migrate_project_task_time"); + + print ''; + + print '
'; + print ''.$langs->trans('MigrationProjectTaskTime')."
\n"; + + $error = 0; + + $db->begin(); + + $sql = "SELECT rowid, fk_task, task_duration"; + $sql.= " FROM ".MAIN_DB_PREFIX."projet_task_time"; + $resql = $db->query($sql); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); + + if ($num) + { + $totaltime = array(); + $oldtime = 0; + + while ($i < $num) + { + $obj = $db->fetch_object($resql); + + if ($obj->task_duration > 0 && strlen($obj->task_duration) < 3) + { + $newtime = $obj->task_duration*60*60; + + $sql2 = "UPDATE ".MAIN_DB_PREFIX."projet_task_time SET"; + $sql2.= " task_duration = ".$newtime; + $sql2.= " WHERE rowid = ".$obj->rowid; + + $resql2=$db->query($sql2); + if (!$resql2) + { + $error++; + dol_print_error($db); + } + print ". "; + $oldtime++; + $totaltime[$obj->fk_task] += $newtime; + } + else + { + $totaltime[$obj->fk_task] += $obj->task_duration; + } + + $i++; + } + + if ($error == 0) + { + if ($oldtime > 0) + { + foreach($totaltime as $taskid => $total_duration) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task SET"; + $sql.= " duration_effective = ".$total_duration; + $sql.= " WHERE rowid = ".$taskid; + + $resql=$db->query($sql); + if (!$resql) + { + $error++; + dol_print_error($db); + } + } + + if ($error == 0) + { + $db->commit(); + } + else + { + $db->rollback(); + } + } + else + { + print $langs->trans('AlreadyDone')."
\n"; + } + } + else + { + dol_print_error($db); + $db->rollback(); + } + } + else + { + print $langs->trans('AlreadyDone')."
\n"; + } + } + else + { + dol_print_error($db); + } + + print ''; +} + /* * Migration directory */ diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang index d9d77c9f3c5..545babe32cb 100644 --- a/htdocs/langs/en_US/install.lang +++ b/htdocs/langs/en_US/install.lang @@ -214,3 +214,6 @@ MigrationProjectTaskActors=Data migration for llx_projet_task_actors table # Migration project user resp MigrationProjectUserResp=Data migration field fk_user_resp of llx_projet to llx_element_contact + +# Migration project task time +MigrationProjectTaskTime=Update time spent in seconds diff --git a/htdocs/langs/fr_FR/install.lang b/htdocs/langs/fr_FR/install.lang index 10f25e82974..727a3e4c20b 100644 --- a/htdocs/langs/fr_FR/install.lang +++ b/htdocs/langs/fr_FR/install.lang @@ -194,25 +194,28 @@ MigrationReopenedContractsNumber=%s contrats modifiés MigrationReopeningContractsNothingToUpdate=Pas ou plus de contrats à réouvrir. # Migration transfert -MigrationBankTransfertsUpdate=Mise a jour des liens entre ecriture bancaire et un transfert entre compte +MigrationBankTransfertsUpdate=Mise à jour des liens entre écriture bancaire et un transfert entre compte MigrationBankTransfertsNothingToUpdate=Aucun lien non à jour # Migration delivery -MigrationShipmentOrderMatching=Mise a jour bon expedition -MigrationDeliveryOrderMatching=Mise a jour bon reception -MigrationDeliveryDetail=Mise a jour bon reception +MigrationShipmentOrderMatching=Mise à jour bon expédition +MigrationDeliveryOrderMatching=Mise à jour bon réception +MigrationDeliveryDetail=Mise à jour bon réception # Migration stock -MigrationStockDetail=Mise a jour valeur en stock des produits +MigrationStockDetail=Mise à jour valeur en stock des produits # Migration menus -MigrationMenusDetail=Mise a jour table des menus dynamiques +MigrationMenusDetail=Mise à jour table des menus dynamiques # Migration delivery address -MigrationDeliveryAddress=Mise a jour des adresses de livraison dans les bons d'expedition +MigrationDeliveryAddress=Mise à jour des adresses de livraison dans les bons d'expédition # Migration project task actors MigrationProjectTaskActors=Migration de la table llx_projet_task_actors # Migration project user resp MigrationProjectUserResp=Migration du champ fk_user_resp de llx_projet vers llx_element_contact + +# Migration project task time +MigrationProjectTaskTime=Mise à jour du temps consommé en secondes diff --git a/htdocs/projet/tasks/task.class.php b/htdocs/projet/tasks/task.class.php index 36149fa7a08..f6d038c5af7 100644 --- a/htdocs/projet/tasks/task.class.php +++ b/htdocs/projet/tasks/task.class.php @@ -60,7 +60,7 @@ class Task extends CommonObject var $timespent_id; var $timespent_duration; var $timespent_date; - var $timespent_user; + var $timespent_fk_user; var $timespent_note; @@ -589,9 +589,8 @@ class Task extends CommonObject /** * \brief Add time spent - * \param user Id utilisateur qui cree - * \param time Time spent - * \param date date + * \param user user id + * \param notrigger 0=launch triggers after, 1=disable triggers */ function addTimeSpent($user, $notrigger=0) { @@ -704,6 +703,66 @@ class Task extends CommonObject } } + /** + * \brief Update time spent + * \param user User id + * \param notrigger 0=launch triggers after, 1=disable triggers + */ + function updateTimeSpent($user, $notrigger=0) + { + $ret = 0; + + // Clean parameters + $this->timespent_duration = intval($this->timespent_duration)+(($this->timespent_duration-intval($this->timespent_duration))*(1+2/3)); + $this->timespent_duration = price2num($this->timespent_duration); + if (isset($this->timespent_note)) $this->timespent_note = trim($this->timespent_note); + + $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_time SET"; + $sql.= " task_date = '".$this->db->idate($this->timespent_date)."',"; + $sql.= " task_duration = ".$this->timespent_duration.","; + $sql.= " fk_user = ".$this->timespent_fk_user.","; + $sql.= " note = ".(isset($this->timespent_note)?"'".addslashes($this->timespent_note)."'":"null"); + $sql.= " WHERE rowid = ".$this->timespent_id; + + dol_syslog(get_class($this)."::updateTimeSpent sql=".$sql, LOG_DEBUG); + if ($this->db->query($sql) ) + { + if (! $notrigger) + { + // Call triggers + include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('TASK_TIMESPENT_MODIFY',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // End call triggers + } + $ret = 1; + } + else + { + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::addTimeSpent error -1 ".$this->error,LOG_ERR); + $ret = -1; + } +/* + if ($ret >= 0) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task"; + $sql.= " SET duration_effective = duration_effective + '".price2num($this->timespent_duration)."'"; + $sql.= " WHERE rowid = ".$this->id; + + dol_syslog(get_class($this)."::addTimeSpent sql=".$sql, LOG_DEBUG); + if (! $this->db->query($sql) ) + { + $this->error=$this->db->lasterror(); + dol_syslog(get_class($this)."::addTimeSpent error -2 ".$this->error, LOG_ERR); + $ret = -2; + } + } +*/ + return $ret; + } + /** * \brief Delete time spent * \param user User that delete diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 55f421f0fef..7e80f109a6d 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -53,6 +53,7 @@ if ($_POST["action"] == 'addtimespent' && $user->rights->projet->creer) $task->timespent_note = $_POST["timespent_note"]; $task->timespent_duration = $_POST["timespent_durationhour"]*60*60; // We store duration in seconds + $task->timespent_duration+= $_POST["timespent_durationmin"]*60; // We store duration in seconds $task->timespent_date = dol_mktime(12,0,0,$_POST["timemonth"],$_POST["timeday"],$_POST["timeyear"]); $task->timespent_fk_user = $_POST["userid"]; @@ -74,7 +75,39 @@ if ($_POST["action"] == 'addtimespent' && $user->rights->projet->creer) if ($_POST["action"] == 'updateline' && ! $_POST["cancel"] && $user->rights->projet->creer) { + $error=0; + if (empty($_POST["timespent_duration_linehour"]) && empty($_POST["timespent_duration_linemin"])) + { + $mesg='
'.$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Duration")).'
'; + $error++; + } + + if (! $error) + { + $task = new Task($db); + + $task->timespent_id = $_POST["lineid"]; + $task->timespent_note = $_POST["timespent_note_line"]; + $task->timespent_duration = $_POST["timespent_duration_linehour"]*60*60; // We store duration in seconds + $task->timespent_duration+= $_POST["timespent_duration_linemin"]*60; // We store duration in seconds + $task->timespent_date = dol_mktime(12,0,0,$_POST["timelinemonth"],$_POST["timelineday"],$_POST["timelineyear"]); + $task->timespent_fk_user = $_POST["userid_line"]; + + $result=$task->updateTimeSpent($user); + if ($result >= 0) + { + + } + else + { + $mesg='
'.$langs->trans($task->error).'
'; + } + } + else + { + $_POST["action"]=''; + } } if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == "yes" && $user->rights->projet->creer) @@ -200,8 +233,7 @@ if ($_GET["id"] > 0) // Duration print ''; - print $html->select_duree('timespent_duration'); - //print ''; + print $html->select_duree('timespent_duration',($_POST['timespent_duration']?$_POST['timespent_duration']:'')); print ''; print ''; @@ -276,16 +308,25 @@ if ($_GET["id"] > 0) print ''; // User - $user->id = $task_time->fk_user; - $user->nom = $task_time->name; - $user->prenom = $task_time->firstname; - print ''.$user->getNomUrl(1).''; + $user->id = $task_time->fk_user; + print ''; + if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid) + { + print $html->select_users($user->id,'userid_line'); + } + else + { + $user->nom = $task_time->name; + $user->prenom = $task_time->firstname; + print $user->getNomUrl(1); + } + print ''; // Note print ''; if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid) { - print ''; + print ''; } else { @@ -297,7 +338,8 @@ if ($_GET["id"] > 0) print ''; if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid) { - print ''; + print ''; + print $html->select_duree('new_duration',$task_time->task_duration); } else { @@ -309,6 +351,7 @@ if ($_GET["id"] > 0) print ''; if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid) { + print ''; print ''; print '
'; print '';