New: Project module support status of project and end date

This commit is contained in:
Laurent Destailleur 2010-01-04 21:45:59 +00:00
parent 2c1d6b245d
commit 2988b561c9
10 changed files with 273 additions and 14 deletions

View File

@ -17,6 +17,7 @@ For users:
- New: task #9640 : Add label for stock movements.
- New: task #9916 : Add FREE text for interventions card.
- New: Can define the new product ref when cloning.
- New: Project module support status of project and end date.
- Fix: bug #28055 : Unable to modify the date of a cloned command.
- Fix: bug #27891.
- Fix: Change of numbering module was not effective.

View File

@ -313,7 +313,7 @@ if ($_POST['action'] == 'updateligne' && $user->rights->ficheinter->creer && $_P
unset($_POST['np_desc']);
unset($_POST['durationhour']);
unset($_POST['durationmin']);
Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$_POST['fichinterid']);
exit;
}
@ -522,7 +522,7 @@ elseif ($fichinterid)
if ($ret == 'html') print '<br>';
}
// Confirmation de la validation de la fiche d'intervention
// Confirmation validation
if ($_GET['action'] == 'validate')
{
$ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$fichinter->id, $langs->trans('ValidateIntervention'), $langs->trans('ConfirmValidateIntervention'), 'confirm_validate','',0,1);
@ -826,7 +826,6 @@ elseif ($fichinterid)
/**
* Barre d'actions
*
*/
print '<div class="tabsAction">';

View File

@ -321,7 +321,7 @@ class Fichinter extends CommonObject
}
/**
* \brief Retourne le libelle du statut de l'intervantion
* \brief Retourne le libelle du statut
* \return string Libelle
*/
function getLibStatut($mode=0)
@ -336,6 +336,8 @@ class Fichinter extends CommonObject
*/
function LibStatut($statut,$mode=0)
{
global $langs;
if ($mode == 0)
{
return $langs->trans($this->statuts[$statut]);

View File

@ -51,4 +51,6 @@ ActivityOnProjectThisYear=Activity on project this year
ChildOfTaks=Child of project/task
NotOwnerOfProject=Not owner of this private project
AffectedTo=Affected to
CantRemoveProject=This project can't be removed as it is referenced by some other objects (invoice, orders or other). See referers tab.
CantRemoveProject=This project can't be removed as it is referenced by some other objects (invoice, orders or other). See referers tab.
ValidateProject=Validate projet
ConfirmValidateProject=Are you sure you want to validate this project ?

View File

@ -51,4 +51,6 @@ ActivityOnProjectThisYear=Activité sur les projets cette année
ChildOfTaks=Fille du projet/tâche
NotOwnerOfProject=Non responsable de ce projet privé
AffectedTo=Affecté à
CantRemoveProject=Ce projet ne peut être supprimé car il est référencé par de nombreux objets (factures, commandes ou autre). voir la liste sur l'onglet Reférents.
CantRemoveProject=Ce projet ne peut être supprimé car il est référencé par de nombreux objets (factures, commandes ou autre). voir la liste sur l'onglet Reférents.
ValidateProject=Valider projet
ConfirmValidateProject=Etes vous sur de vouloir valider ce projet ?

View File

@ -40,13 +40,17 @@ class Project extends CommonObject
var $id;
var $ref;
var $statut;
var $title;
var $date_c;
var $date_m;
var $date_start;
var $date_end;
var $socid;
var $user_resp_id;
var $statuts_short;
var $statuts;
/**
* \brief Constructeur de la classe
@ -56,6 +60,9 @@ class Project extends CommonObject
{
$this->db = $DB;
$this->societe = new Societe($DB);
$this->statuts_short=array(0=>'Draft',1=>'Validated',2=>'Closed');
$this->statuts=array(0=>'Draft',1=>'Validated',2=>'Closed');
}
/*
@ -73,13 +80,14 @@ class Project extends CommonObject
return -1;
}
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (ref, title, fk_soc, fk_user_creat, fk_user_resp, datec, dateo, fk_statut)";
$sql = "INSERT INTO ".MAIN_DB_PREFIX."projet (ref, title, fk_soc, fk_user_creat, fk_user_resp, datec, dateo, datee, fk_statut)";
$sql.= " VALUES ('".addslashes($this->ref)."', '".addslashes($this->title)."',";
$sql.= " ".($this->socid > 0?$this->socid:"null").",";
$sql.= " ".$user->id.",";
$sql.= " ".($this->user_resp_id>0?$this->user_resp_id:'null').",";
$sql.= " ".($this->datec!=''?$this->db->idate($this->datec):'null').",";
$sql.= " ".($this->dateo!=''?$this->db->idate($this->dateo):'null').",";
$sql.= " ".($this->datee!=''?$this->db->idate($this->datee):'null').",";
$sql.= " 0)";
dol_syslog("Project::create sql=".$sql,LOG_DEBUG);
@ -100,6 +108,12 @@ class Project extends CommonObject
}
/**
* Update a project
*
* @param unknown_type $user
* @return unknown
*/
function update($user)
{
if (strlen(trim($this->ref)) > 0)
@ -109,8 +123,10 @@ class Project extends CommonObject
$sql.= ", title = '".$this->title."'";
$sql.= ", fk_soc = ".($this->socid > 0?$this->socid:"null");
$sql.= ", fk_user_resp = ".$this->user_resp_id;
$sql.= ", fk_statut = ".$this->statut;
$sql.= ", datec=".($this->datec!=''?$this->db->idate($this->datec):'null');
$sql.= ", dateo=".($this->dateo!=''?$this->db->idate($this->dateo):'null');
$sql.= ", dateo=".($this->date_start!=''?$this->db->idate($this->date_start):'null');
$sql.= ", datee=".($this->date_end!=''?$this->db->idate($this->date_end):'null');
$sql.= " WHERE rowid = ".$this->id;
dol_syslog("Project::Update sql=".$sql,LOG_DEBUG);
@ -143,7 +159,9 @@ class Project extends CommonObject
*/
function fetch($id,$ref='')
{
$sql = "SELECT rowid, ref, title, datec, tms, dateo, fk_soc, fk_user_creat, fk_user_resp, fk_statut, note";
if (empty($id) && empty($ref)) return -1;
$sql = "SELECT rowid, ref, title, datec, tms, dateo, datee, fk_soc, fk_user_creat, fk_user_resp, fk_statut, note";
$sql.= " FROM ".MAIN_DB_PREFIX."projet";
if ($ref) $sql.= " WHERE ref='".$ref."'";
else $sql.= " WHERE rowid=".$id;
@ -163,6 +181,7 @@ class Project extends CommonObject
$this->date_c = $this->db->jdate($obj->datec);
$this->date_m = $this->db->jdate($obj->tms);
$this->date_start = $this->db->jdate($obj->dateo);
$this->date_end = $this->db->jdate($obj->datee);
$this->note = $obj->note;
$this->socid = $obj->fk_soc;
$this->societe->id = $obj->fk_soc; // For backward compatibility
@ -297,6 +316,112 @@ class Project extends CommonObject
}
}
/**
* \brief Validate a project
* \param user User that validate
* \return int <0 if KO, >0 if OK
*/
function setValid($user, $outputdir)
{
global $langs, $conf;
if ($this->statut != 1)
{
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."projet";
$sql.= " SET fk_statut = 1";
$sql.= " WHERE rowid = ".$this->id;
$sql.= " AND entity = ".$conf->entity;
$sql.= " AND fk_statut = 0";
dol_syslog("Project::setValid sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('PROJECT_VALIDATE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
if (! $error)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
$this->error=join(',',$this->errors);
dol_syslog("Project::setValid ".$this->error,LOG_ERR);
return -1;
}
}
else
{
$this->db->rollback();
$this->error=$this->db->lasterror();
dol_syslog("Project::setValid ".$this->error,LOG_ERR);
return -1;
}
}
}
/**
* \brief Close a project
* \param user User that validate
* \return int <0 if KO, >0 if OK
*/
function setClose($user, $outputdir)
{
global $langs, $conf;
if ($this->statut != 1)
{
$this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."projet";
$sql.= " SET fk_statut = 2";
$sql.= " WHERE rowid = ".$this->id;
$sql.= " AND entity = ".$conf->entity;
$sql.= " AND fk_statut = 1";
dol_syslog("Project::setClose sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('PROJECT_CLOSE',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; }
// Fin appel triggers
if (! $error)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
$this->error=join(',',$this->errors);
dol_syslog("Project::setClose ".$this->error,LOG_ERR);
return -1;
}
}
else
{
$this->db->rollback();
$this->error=$this->db->lasterror();
dol_syslog("Project::setClose ".$this->error,LOG_ERR);
return -1;
}
}
}
/**
* \brief Create a task into project
* \param user Id user that create
@ -553,6 +678,54 @@ class Project extends CommonObject
}
/**
* \brief Return status label of object
* \return string Label
*/
function getLibStatut($mode=0)
{
return $this->LibStatut($this->statut,$mode);
}
/**
* \brief Renvoi status label for a status
* \param statut id statut
* \return string Label
*/
function LibStatut($statut,$mode=0)
{
global $langs;
if ($mode == 0)
{
return $langs->trans($this->statuts[$statut]);
}
if ($mode == 1)
{
return $langs->trans($this->statuts_short[$statut]);
}
if ($mode == 2)
{
if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts_short[$statut]);
if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]);
}
if ($mode == 3)
{
if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0');
if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4');
}
if ($mode == 4)
{
if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
if ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
}
if ($mode == 5)
{
if ($statut==0) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut0');
if ($statut==1) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut1');
}
}
/**
* \brief Renvoie nom clicable (avec eventuellement le picto)
* \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul

View File

@ -93,6 +93,9 @@ if ($projet->user->id) print $projet->user->getNomUrl(1);
else print $langs->trans('SharedProject');
print '</td></tr>';
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$projet->getLibStatut(4).'</td></tr>';
print '</table>';
print '</div>';
@ -101,6 +104,7 @@ print '</div>';
/*
* Factures
*/
$listofreferent=array(
'propal'=>array(
'title'=>"ListProposalsAssociatedProject",

View File

@ -31,6 +31,8 @@ if ($conf->propal->enabled) require_once(DOL_DOCUMENT_ROOT."/propal.class.php");
if ($conf->facture->enabled) require_once(DOL_DOCUMENT_ROOT."/facture.class.php");
if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
$langs->load("projects");
$projetid='';
$ref='';
if (isset($_GET["id"])) { $projetid=$_GET["id"]; }
@ -122,12 +124,14 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->projet-
if (! $error)
{
$projet = new Project($db);
$projet->id = $_POST["id"];
$projet->fetch($_POST["id"]);
$projet->ref = $_POST["ref"];
$projet->title = $_POST["title"];
$projet->socid = $_POST["socid"];
$projet->user_resp_id = $_POST["officer_project"];
$projet->dateo = dol_mktime(12,0,0,$_POST['projectmonth'],$_POST['projectday'],$_POST['projectyear']);
$projet->date_start = dol_mktime(12,0,0,$_POST['projectmonth'],$_POST['projectday'],$_POST['projectyear']);
$projet->date_end = dol_mktime(12,0,0,$_POST['projectendmonth'],$_POST['projectendday'],$_POST['projectendyear']);
$result=$projet->update($user);
@ -140,6 +144,28 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"] && $user->rights->projet-
}
}
if ($_REQUEST['action'] == 'confirm_validate' && $_REQUEST['confirm'] == 'yes')
{
$project = new Project($db);
$project->fetch($_GET["id"]);
$result = $project->setValid($user, $conf->projet->outputdir);
if ($result >= 0)
{
/* $outputlangs = $langs;
if (! empty($_REQUEST['lang_id']))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
}
$result=projet_create($db, $projet, $_REQUEST['model'], $outputlangs);
*/ }
else
{
$mesg='<div class="error">'.$project->error.'</div>';
}
}
if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == "yes" && $user->rights->projet->supprimer)
{
$projet = new Project($db);
@ -206,11 +232,16 @@ if ($_GET["action"] == 'create' && $user->rights->projet->creer)
}
print '</td></tr>';
// Date
// Date start
print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
print $html->select_date('','project');
print '</td></tr>';
// Date end
print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
print $html->select_date(-1,'projectend');
print '</td></tr>';
print '<tr><td colspan="2" align="center"><input type="submit" class="button" value="'.$langs->trans("Create").'"></td></tr>';
print '</table>';
print '</form>';
@ -233,12 +264,20 @@ else
$head=project_prepare_head($projet);
dol_fiche_head($head, 'project', $langs->trans("Project"),0,'project');
// Confirmation validation
if ($_GET['action'] == 'validate')
{
$ret=$html->form_confirm($_SERVER["PHP_SELF"].'?id='.$projet->id, $langs->trans('ValidateProject'), $langs->trans('ConfirmValidateProject'), 'confirm_validate','',0,1);
if ($ret == 'html') print '<br>';
}
// Confirmation delete
if ($_GET["action"] == 'delete')
{
$ret=$html->form_confirm($_SERVER["PHP_SELF"]."?id=".$_GET["id"],$langs->trans("DeleteAProject"),$langs->trans("ConfirmDeleteAProject"),"confirm_delete",'','',1);
if ($ret == 'html') print '<br>';
}
if ($_GET["action"] == 'edit')
{
print '<form method="post" action="fiche.php">';
@ -264,11 +303,19 @@ else
$html->select_users($projet->user_resp_id,'officer_project',1);
print '</td></tr>';
// Date
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$projet->getLibStatut(4).'</td></tr>';
// Date start
print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
print $html->select_date($projet->date_start,'project');
print '</td></tr>';
// Date end
print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
print $html->select_date($projet->date_end?$projet->date_end:-1,'projectend');
print '</td></tr>';
print '<tr><td align="center" colspan="2"><input name="update" class="button" type="submit" value="'.$langs->trans("Modify").'"> &nbsp; <input type="submit" class="button" name="cancel" Value="'.$langs->trans("Cancel").'"></td></tr>';
print '</table>';
print '</form>';
@ -297,11 +344,19 @@ else
else print $langs->trans('SharedProject');
print '</td></tr>';
// Date
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$projet->getLibStatut(4).'</td></tr>';
// Date start
print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
print dol_print_date($projet->date_start,'day');
print '</td></tr>';
// Date end
print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
print dol_print_date($projet->date_end,'day');
print '</td></tr>';
print '</table>';
}
@ -314,10 +369,26 @@ else
if ($_GET["action"] != "edit")
{
// Validate
if ($projet->statut == 0 && $user->rights->projet->creer)
{
print '<a class="butAction" href="fiche.php?id='.$_GET["id"].'&action=validate"';
print '>'.$langs->trans("Valid").'</a>';
}
// Modify
if ($user->rights->projet->creer)
{
print '<a class="butAction" href="fiche.php?id='.$projet->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>';
}
// Close
if ($user->rights->projet->creer)
{
print '<a class="butAction" href="fiche.php?id='.$projet->id.'&amp;action=close">'.$langs->trans("Close").'</a>';
}
// Delete
if ($user->rights->projet->supprimer)
{
print '<a class="butActionDelete" href="fiche.php?id='.$projet->id.'&amp;action=delete">'.$langs->trans("Delete").'</a>';

View File

@ -218,6 +218,9 @@ else
else print $langs->trans('SharedProject');
print '</td></tr>';
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$projet->getLibStatut(4).'</td></tr>';
print '</table>';
print '<input type="hidden" name="action" value="addtime">';

View File

@ -494,6 +494,8 @@ class Societe extends CommonObject
global $langs;
global $conf;
if (empty($socid) && empty($ref)) return -1;
// Init data for telephonie module
if ($conf->telephonie->enabled && $user && $user->id)
{