Fix: management of time spent in task card
Fix: Update time spent in seconds
This commit is contained in:
parent
ed44821987
commit
4adf45647a
@ -172,6 +172,12 @@ 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'
|
// dans la 4eme colonne, le texte 'OK' si fait ou 'AlreadyDone' si rien n'est fait ou 'Error'
|
||||||
|
|
||||||
|
|
||||||
|
$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
|
// Script pour V2 -> V2.1
|
||||||
migrate_paiements($db,$langs,$conf);
|
migrate_paiements($db,$langs,$conf);
|
||||||
|
|
||||||
@ -234,10 +240,9 @@ if (isset($_POST['action']) && preg_match('/upgrade/i',$_POST["action"]))
|
|||||||
migrate_directories($db,$langs,$conf,'/compta','/banque');
|
migrate_directories($db,$langs,$conf,'/compta','/banque');
|
||||||
|
|
||||||
migrate_directories($db,$langs,$conf,'/societe','/mycompany');
|
migrate_directories($db,$langs,$conf,'/societe','/mycompany');
|
||||||
|
}
|
||||||
|
|
||||||
// Script for -> V2.8
|
// Script for -> V2.8
|
||||||
$versiontoarray=explode('.',$versionto);
|
|
||||||
$afterversionarray=explode('.','2.7.9');
|
$afterversionarray=explode('.','2.7.9');
|
||||||
$beforeversionarray=explode('.','2.8.9');
|
$beforeversionarray=explode('.','2.8.9');
|
||||||
//print $versionto.' '.versioncompare($versiontoarray,$afterversionarray).' '.versioncompare($versiontoarray,$beforeversionarray);
|
//print $versionto.' '.versioncompare($versiontoarray,$afterversionarray).' '.versioncompare($versiontoarray,$beforeversionarray);
|
||||||
@ -262,6 +267,14 @@ if (isset($_POST['action']) && preg_match('/upgrade/i',$_POST["action"]))
|
|||||||
migrate_project_task_actors($db,$langs,$conf);
|
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.
|
// On commit dans tous les cas.
|
||||||
// La procedure etant concue pour pouvoir passer plusieurs fois quelquesoit la situation.
|
// La procedure etant concue pour pouvoir passer plusieurs fois quelquesoit la situation.
|
||||||
$db->commit();
|
$db->commit();
|
||||||
@ -2704,6 +2717,116 @@ function migrate_relationship_tables($db,$langs,$conf,$table,$fk_source,$sourcet
|
|||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Migrate duration in seconds
|
||||||
|
*/
|
||||||
|
function migrate_project_task_time($db,$langs,$conf)
|
||||||
|
{
|
||||||
|
dolibarr_install_syslog("upgrade2::migrate_project_task_time");
|
||||||
|
|
||||||
|
print '<tr><td colspan="4">';
|
||||||
|
|
||||||
|
print '<br>';
|
||||||
|
print '<b>'.$langs->trans('MigrationProjectTaskTime')."</b><br>\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')."<br>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dol_print_error($db);
|
||||||
|
$db->rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print $langs->trans('AlreadyDone')."<br>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dol_print_error($db);
|
||||||
|
}
|
||||||
|
|
||||||
|
print '</td></tr>';
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Migration directory
|
* Migration directory
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -214,3 +214,6 @@ MigrationProjectTaskActors=Data migration for llx_projet_task_actors table
|
|||||||
|
|
||||||
# Migration project user resp
|
# Migration project user resp
|
||||||
MigrationProjectUserResp=Data migration field fk_user_resp of llx_projet to llx_element_contact
|
MigrationProjectUserResp=Data migration field fk_user_resp of llx_projet to llx_element_contact
|
||||||
|
|
||||||
|
# Migration project task time
|
||||||
|
MigrationProjectTaskTime=Update time spent in seconds
|
||||||
|
|||||||
@ -194,25 +194,28 @@ MigrationReopenedContractsNumber=%s contrats modifiés
|
|||||||
MigrationReopeningContractsNothingToUpdate=Pas ou plus de contrats à réouvrir.
|
MigrationReopeningContractsNothingToUpdate=Pas ou plus de contrats à réouvrir.
|
||||||
|
|
||||||
# Migration transfert
|
# 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
|
MigrationBankTransfertsNothingToUpdate=Aucun lien non à jour
|
||||||
|
|
||||||
# Migration delivery
|
# Migration delivery
|
||||||
MigrationShipmentOrderMatching=Mise a jour bon expedition
|
MigrationShipmentOrderMatching=Mise à jour bon expédition
|
||||||
MigrationDeliveryOrderMatching=Mise a jour bon reception
|
MigrationDeliveryOrderMatching=Mise à jour bon réception
|
||||||
MigrationDeliveryDetail=Mise a jour bon reception
|
MigrationDeliveryDetail=Mise à jour bon réception
|
||||||
|
|
||||||
# Migration stock
|
# Migration stock
|
||||||
MigrationStockDetail=Mise a jour valeur en stock des produits
|
MigrationStockDetail=Mise à jour valeur en stock des produits
|
||||||
|
|
||||||
# Migration menus
|
# Migration menus
|
||||||
MigrationMenusDetail=Mise a jour table des menus dynamiques
|
MigrationMenusDetail=Mise à jour table des menus dynamiques
|
||||||
|
|
||||||
# Migration delivery address
|
# 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
|
# Migration project task actors
|
||||||
MigrationProjectTaskActors=Migration de la table llx_projet_task_actors
|
MigrationProjectTaskActors=Migration de la table llx_projet_task_actors
|
||||||
|
|
||||||
# Migration project user resp
|
# Migration project user resp
|
||||||
MigrationProjectUserResp=Migration du champ fk_user_resp de llx_projet vers llx_element_contact
|
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
|
||||||
|
|||||||
@ -60,7 +60,7 @@ class Task extends CommonObject
|
|||||||
var $timespent_id;
|
var $timespent_id;
|
||||||
var $timespent_duration;
|
var $timespent_duration;
|
||||||
var $timespent_date;
|
var $timespent_date;
|
||||||
var $timespent_user;
|
var $timespent_fk_user;
|
||||||
var $timespent_note;
|
var $timespent_note;
|
||||||
|
|
||||||
|
|
||||||
@ -589,9 +589,8 @@ class Task extends CommonObject
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Add time spent
|
* \brief Add time spent
|
||||||
* \param user Id utilisateur qui cree
|
* \param user user id
|
||||||
* \param time Time spent
|
* \param notrigger 0=launch triggers after, 1=disable triggers
|
||||||
* \param date date
|
|
||||||
*/
|
*/
|
||||||
function addTimeSpent($user, $notrigger=0)
|
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
|
* \brief Delete time spent
|
||||||
* \param user User that delete
|
* \param user User that delete
|
||||||
|
|||||||
@ -53,6 +53,7 @@ if ($_POST["action"] == 'addtimespent' && $user->rights->projet->creer)
|
|||||||
|
|
||||||
$task->timespent_note = $_POST["timespent_note"];
|
$task->timespent_note = $_POST["timespent_note"];
|
||||||
$task->timespent_duration = $_POST["timespent_durationhour"]*60*60; // We store duration in seconds
|
$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_date = dol_mktime(12,0,0,$_POST["timemonth"],$_POST["timeday"],$_POST["timeyear"]);
|
||||||
$task->timespent_fk_user = $_POST["userid"];
|
$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)
|
if ($_POST["action"] == 'updateline' && ! $_POST["cancel"] && $user->rights->projet->creer)
|
||||||
{
|
{
|
||||||
|
$error=0;
|
||||||
|
|
||||||
|
if (empty($_POST["timespent_duration_linehour"]) && empty($_POST["timespent_duration_linemin"]))
|
||||||
|
{
|
||||||
|
$mesg='<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Duration")).'</div>';
|
||||||
|
$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='<div class="error">'.$langs->trans($task->error).'</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$_POST["action"]='';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == "yes" && $user->rights->projet->creer)
|
if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == "yes" && $user->rights->projet->creer)
|
||||||
@ -200,8 +233,7 @@ if ($_GET["id"] > 0)
|
|||||||
|
|
||||||
// Duration
|
// Duration
|
||||||
print '<td nowrap="nowrap" align="right">';
|
print '<td nowrap="nowrap" align="right">';
|
||||||
print $html->select_duree('timespent_duration');
|
print $html->select_duree('timespent_duration',($_POST['timespent_duration']?$_POST['timespent_duration']:''));
|
||||||
//print '<input size="4" type="text" class="flat" name="timespent_duration" value="">';
|
|
||||||
print '</td>';
|
print '</td>';
|
||||||
|
|
||||||
print '<td align="center">';
|
print '<td align="center">';
|
||||||
@ -277,15 +309,24 @@ if ($_GET["id"] > 0)
|
|||||||
|
|
||||||
// User
|
// User
|
||||||
$user->id = $task_time->fk_user;
|
$user->id = $task_time->fk_user;
|
||||||
|
print '<td>';
|
||||||
|
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
|
||||||
|
{
|
||||||
|
print $html->select_users($user->id,'userid_line');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
$user->nom = $task_time->name;
|
$user->nom = $task_time->name;
|
||||||
$user->prenom = $task_time->firstname;
|
$user->prenom = $task_time->firstname;
|
||||||
print '<td>'.$user->getNomUrl(1).'</td>';
|
print $user->getNomUrl(1);
|
||||||
|
}
|
||||||
|
print '</td>';
|
||||||
|
|
||||||
// Note
|
// Note
|
||||||
print '<td align="left">';
|
print '<td align="left">';
|
||||||
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
|
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
|
||||||
{
|
{
|
||||||
print '<textarea name="timespent_note" cols="80" rows="4">'.$task_time->note.'</textarea>';
|
print '<textarea name="timespent_note_line" cols="80" rows="'.ROWS_3.'">'.$task_time->note.'</textarea>';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -297,7 +338,8 @@ if ($_GET["id"] > 0)
|
|||||||
print '<td align="right">';
|
print '<td align="right">';
|
||||||
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
|
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
|
||||||
{
|
{
|
||||||
print '<input size="4" type="text" class="flat" name="timespent_duration" value="'.$task_time->task_duration.'">';
|
print '<input type="hidden" name="old_duration" value="'.$task_time->task_duration.'">';
|
||||||
|
print $html->select_duree('new_duration',$task_time->task_duration);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -309,6 +351,7 @@ if ($_GET["id"] > 0)
|
|||||||
print '<td align="center" valign="middle" width="80">';
|
print '<td align="center" valign="middle" width="80">';
|
||||||
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
|
if ($_GET['action'] == 'editline' && $_GET['lineid'] == $task_time->rowid)
|
||||||
{
|
{
|
||||||
|
print '<input type="hidden" name="lineid" value="'.$_GET['lineid'].'">';
|
||||||
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
|
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
|
||||||
print '<br>';
|
print '<br>';
|
||||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
|
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user