From 2988b561c97e07b004ab3290759e1a8755dbe962 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 4 Jan 2010 21:45:59 +0000 Subject: [PATCH] New: Project module support status of project and end date --- ChangeLog | 1 + htdocs/fichinter/fiche.php | 5 +- htdocs/fichinter/fichinter.class.php | 4 +- htdocs/langs/en_US/projects.lang | 4 +- htdocs/langs/fr_FR/projects.lang | 4 +- htdocs/project.class.php | 179 ++++++++++++++++++++++++++- htdocs/projet/element.php | 4 + htdocs/projet/fiche.php | 81 +++++++++++- htdocs/projet/tasks/fiche.php | 3 + htdocs/societe.class.php | 2 + 10 files changed, 273 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index f000dbe026b..4841827aabd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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. diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index bd2905dc3d4..d044cf31777 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -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 '
'; } - // 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 '
'; diff --git a/htdocs/fichinter/fichinter.class.php b/htdocs/fichinter/fichinter.class.php index 2278d0c4ebc..a6491f2a8c3 100644 --- a/htdocs/fichinter/fichinter.class.php +++ b/htdocs/fichinter/fichinter.class.php @@ -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]); diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index dcb9136be6e..8c2fba7995f 100755 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -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. \ No newline at end of file +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 ? diff --git a/htdocs/langs/fr_FR/projects.lang b/htdocs/langs/fr_FR/projects.lang index 0d69eebb46c..b591e81379a 100755 --- a/htdocs/langs/fr_FR/projects.lang +++ b/htdocs/langs/fr_FR/projects.lang @@ -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. \ No newline at end of file +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 ? \ No newline at end of file diff --git a/htdocs/project.class.php b/htdocs/project.class.php index 2bc070d401d..a653f47c44e 100644 --- a/htdocs/project.class.php +++ b/htdocs/project.class.php @@ -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 diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index cf4dd760c4f..20d52e5d611 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -93,6 +93,9 @@ if ($projet->user->id) print $projet->user->getNomUrl(1); else print $langs->trans('SharedProject'); print ''; +// Statut +print ''.$langs->trans("Status").''.$projet->getLibStatut(4).''; + print ''; print '
'; @@ -101,6 +104,7 @@ print ''; /* * Factures */ + $listofreferent=array( 'propal'=>array( 'title'=>"ListProposalsAssociatedProject", diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php index 8d0de7806be..9c617a9a8c7 100644 --- a/htdocs/projet/fiche.php +++ b/htdocs/projet/fiche.php @@ -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='
'.$project->error.'
'; + } +} + 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 ''; - // Date + // Date start print ''.$langs->trans("DateStart").''; print $html->select_date('','project'); print ''; + // Date end + print ''.$langs->trans("DateEnd").''; + print $html->select_date(-1,'projectend'); + print ''; + print ''; print ''; print ''; @@ -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 '
'; + } + // 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 '
'; } + if ($_GET["action"] == 'edit') { print '
'; @@ -264,11 +303,19 @@ else $html->select_users($projet->user_resp_id,'officer_project',1); print ''; - // Date + // Statut + print ''.$langs->trans("Status").''.$projet->getLibStatut(4).''; + + // Date start print ''.$langs->trans("DateStart").''; print $html->select_date($projet->date_start,'project'); print ''; + // Date end + print ''.$langs->trans("DateEnd").''; + print $html->select_date($projet->date_end?$projet->date_end:-1,'projectend'); + print ''; + print '   '; print ''; print '
'; @@ -297,11 +344,19 @@ else else print $langs->trans('SharedProject'); print ''; - // Date + // Statut + print ''.$langs->trans("Status").''.$projet->getLibStatut(4).''; + + // Date start print ''.$langs->trans("DateStart").''; print dol_print_date($projet->date_start,'day'); print ''; + // Date end + print ''.$langs->trans("DateEnd").''; + print dol_print_date($projet->date_end,'day'); + print ''; + print ''; } @@ -314,10 +369,26 @@ else if ($_GET["action"] != "edit") { + // Validate + if ($projet->statut == 0 && $user->rights->projet->creer) + { + print ''.$langs->trans("Valid").''; + } + + // Modify if ($user->rights->projet->creer) { print ''.$langs->trans("Modify").''; } + + // Close + if ($user->rights->projet->creer) + { + print ''.$langs->trans("Close").''; + } + + // Delete if ($user->rights->projet->supprimer) { print ''.$langs->trans("Delete").''; diff --git a/htdocs/projet/tasks/fiche.php b/htdocs/projet/tasks/fiche.php index 0d868325090..eb59defd24c 100644 --- a/htdocs/projet/tasks/fiche.php +++ b/htdocs/projet/tasks/fiche.php @@ -218,6 +218,9 @@ else else print $langs->trans('SharedProject'); print ''; + // Statut + print ''.$langs->trans("Status").''.$projet->getLibStatut(4).''; + print ''; print ''; diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php index 99d25294374..3381c340566 100644 --- a/htdocs/societe.class.php +++ b/htdocs/societe.class.php @@ -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) {