Fix: management of time spent in task card
Fix: Update time spent in seconds
This commit is contained in:
parent
ed44821987
commit
4adf45647a
@ -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 '</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
|
||||
*/
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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='<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)
|
||||
@ -200,8 +233,7 @@ if ($_GET["id"] > 0)
|
||||
|
||||
// Duration
|
||||
print '<td nowrap="nowrap" align="right">';
|
||||
print $html->select_duree('timespent_duration');
|
||||
//print '<input size="4" type="text" class="flat" name="timespent_duration" value="">';
|
||||
print $html->select_duree('timespent_duration',($_POST['timespent_duration']?$_POST['timespent_duration']:''));
|
||||
print '</td>';
|
||||
|
||||
print '<td align="center">';
|
||||
@ -276,16 +308,25 @@ if ($_GET["id"] > 0)
|
||||
print '</td>';
|
||||
|
||||
// User
|
||||
$user->id = $task_time->fk_user;
|
||||
$user->nom = $task_time->name;
|
||||
$user->prenom = $task_time->firstname;
|
||||
print '<td>'.$user->getNomUrl(1).'</td>';
|
||||
$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->prenom = $task_time->firstname;
|
||||
print $user->getNomUrl(1);
|
||||
}
|
||||
print '</td>';
|
||||
|
||||
// Note
|
||||
print '<td align="left">';
|
||||
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
|
||||
{
|
||||
@ -297,7 +338,8 @@ if ($_GET["id"] > 0)
|
||||
print '<td align="right">';
|
||||
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
|
||||
{
|
||||
@ -309,6 +351,7 @@ if ($_GET["id"] > 0)
|
||||
print '<td align="center" valign="middle" width="80">';
|
||||
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 '<br>';
|
||||
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'">';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user