diff --git a/htdocs/fichinter/fichinter.class.php b/htdocs/fichinter/fichinter.class.php index 84bac82ffae..dc269aefc1f 100644 --- a/htdocs/fichinter/fichinter.class.php +++ b/htdocs/fichinter/fichinter.class.php @@ -35,187 +35,197 @@ require_once(DOL_DOCUMENT_ROOT ."/notify.class.php"); */ class Fichinter { - var $id; - var $db; - var $socidp; - var $author; - var $ref; - var $date; - var $duree; - var $note; - var $projet_id; + var $id; + var $db; + var $socidp; + var $author; + var $ref; + var $date; + var $duree; + var $note; + var $projet_id; - function Fichinter($DB, $soc_idp="") + /** + * \brief Constructeur de la classe + * \param DB Handler accès base de données + * \param soc_idp Id societe + */ + function Fichinter($DB, $soc_idp="") { - $this->db = $DB ; - $this->socidp = $soc_idp; - $this->products = array(); - $this->projet_id = 0; + global $langs; + + $this->db = $DB ; + $this->socidp = $soc_idp; + $this->products = array(); + $this->projet_id = 0; + + // Statut 0=brouillon, 1=validé + $this->statuts[0]=$langs->trans("Draft"); + $this->statuts[1]=$langs->trans("Validated"); } - function add_product($idproduct) + + function add_product($idproduct) { - if ($idproduct > 0) - { - $i = sizeof($this->products); - $this->products[$i] = $idproduct; - } + if ($idproduct > 0) + { + $i = sizeof($this->products); + $this->products[$i] = $idproduct; + } } - /* - * \brief Crée une fiche intervention en base - * - */ - function create() + /* + * \brief Crée une fiche intervention en base + * + */ + function create() { - if (!strlen($this->duree)) { $this->duree = 0; } + if (!strlen($this->duree)) { $this->duree = 0; } + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter (fk_soc, datei, datec, ref, fk_user_author, note, duree"; + if ($this->projet_id) { + $sql .= ",fk_projet"; + } + $sql .= ") "; + $sql .= " VALUES ($this->socidp, $this->date, now(), '$this->ref', $this->author, '$this->note', $this->duree"; + if ($this->projet_id) { + $sql .= ", $this->projet_id"; + } + $sql .= ")"; + $sqlok = 0; + + $result=$this->db->query($sql); + if ($result) + { + return $this->db->last_insert_id(MAIN_DB_PREFIX."fichinter"); + } + else + { + return -1; + } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."fichinter (fk_soc, datei, datec, ref, fk_user_author, note, duree"; - if ($this->projet_id) { - $sql .= ",fk_projet"; - } - $sql .= ") "; - $sql .= " VALUES ($this->socidp, $this->date, now(), '$this->ref', $this->author, '$this->note', $this->duree"; - if ($this->projet_id) { - $sql .= ", $this->projet_id"; - } - $sql .= ")"; - $sqlok = 0; - - $result=$this->db->query($sql); - if ($result) - { - return $this->db->last_insert_id(MAIN_DB_PREFIX."fichinter"); - } - else - { - return -1; - } - } - /* - * - * - * - */ - function update($id) + /* + * + * + */ + function update($id) { - if (! strlen($this->projet_id)) - { - $this->projet_id = 0; - } + if (! strlen($this->projet_id)) + { + $this->projet_id = 0; + } - /* - * Insertion dans la base - */ - $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET "; - $sql .= " datei = $this->date"; - $sql .= ", note = '$this->note'"; - $sql .= ", duree = $this->duree"; - $sql .= ", fk_projet = $this->projet_id"; - $sql .= " WHERE rowid = $id"; - - if (! $this->db->query($sql) ) - { - - print $this->db->error() . '
'.$sql; - } - return 1; - } - /* - * - * - * - */ - function get_new_num($prefix_comm) - { - - $sql = "SELECT max(ref) FROM ".MAIN_DB_PREFIX."fichinter WHERE ref like 'FI-".$prefix_comm."-%'"; - - if ($this->db->query($sql) ) - { - if ($this->db->num_rows()) - { - $row = $this->db->fetch_row(0); - $num = $row[0]; - /* - *$num = substr($num, strlen($num) - 4, 4); - *$num = $num + 1; - *$num = '0000' . $num; - *$num = 'FI-' . $prefix_comm . '-' . substr($num, strlen($num) - 4, 4); - */ - $num = substr($num, 3); - $num = substr(strstr($num, "-"),1); + /* + * Insertion dans la base + */ + $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET "; + $sql .= " datei = $this->date"; + $sql .= ", note = '$this->note'"; + $sql .= ", duree = $this->duree"; + $sql .= ", fk_projet = $this->projet_id"; + $sql .= " WHERE rowid = $id"; - $num = $num + 1; - //$num = '0000' . $num; - //$num = 'FI-' . $prefix_comm . '-' . substr($num, strlen($num) - 4, 4); - $num = 'FI-' . $prefix_comm . '-' . $num; - return $num; - } - } - else - { - print $this->db->error(); - } + if (! $this->db->query($sql) ) + { + + print $this->db->error() . '
'.$sql; + } + return 1; } - - /* - * - * - */ - function fetch($rowid) + + /* + * + * + */ + function get_new_num($prefix_comm) { - - $sql = "SELECT ref,note,fk_soc,fk_statut,duree,".$this->db->pdate(datei)."as di, fk_projet FROM ".MAIN_DB_PREFIX."fichinter WHERE rowid=$rowid;"; - - if ($this->db->query($sql) ) - { - if ($this->db->num_rows()) - { - $obj = $this->db->fetch_object(); - - $this->id = $rowid; - $this->date = $obj->di; - $this->duree = $obj->duree; - $this->ref = $obj->ref; - $this->note = stripslashes($obj->note); - $this->societe_id = $obj->fk_soc; - $this->projet_id = $obj->fk_projet; - $this->statut = $obj->fk_statut; - - $this->db->free(); - return 1; - } - } - else - { - print $this->db->error(); - return 0; - } + + $sql = "SELECT max(ref) FROM ".MAIN_DB_PREFIX."fichinter WHERE ref like 'FI-".$prefix_comm."-%'"; + + if ($this->db->query($sql) ) + { + if ($this->db->num_rows()) + { + $row = $this->db->fetch_row(0); + $num = $row[0]; + /* + *$num = substr($num, strlen($num) - 4, 4); + *$num = $num + 1; + *$num = '0000' . $num; + *$num = 'FI-' . $prefix_comm . '-' . substr($num, strlen($num) - 4, 4); + */ + $num = substr($num, 3); + $num = substr(strstr($num, "-"),1); + + $num = $num + 1; + //$num = '0000' . $num; + //$num = 'FI-' . $prefix_comm . '-' . substr($num, strlen($num) - 4, 4); + $num = 'FI-' . $prefix_comm . '-' . $num; + return $num; + } + } + else + { + print $this->db->error(); + } } - /* - * - * - * - */ - function valid($userid, $outputdir) + + /* + * + * + */ + function fetch($rowid) + { + + $sql = "SELECT ref,note,fk_soc,fk_statut,duree,".$this->db->pdate(datei)."as di, fk_projet FROM ".MAIN_DB_PREFIX."fichinter WHERE rowid=$rowid;"; + + if ($this->db->query($sql) ) + { + if ($this->db->num_rows()) + { + $obj = $this->db->fetch_object(); + + $this->id = $rowid; + $this->date = $obj->di; + $this->duree = $obj->duree; + $this->ref = $obj->ref; + $this->note = stripslashes($obj->note); + $this->societe_id = $obj->fk_soc; + $this->projet_id = $obj->fk_projet; + $this->statut = $obj->fk_statut; + + $this->db->free(); + return 1; + } + } + else + { + print $this->db->error(); + return 0; + } + } + + /* + * + * + */ + function valid($userid, $outputdir) { $action_notify = 1; // ne pas modifier cette valeur - + $this->fetch($this->id); - + $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET fk_statut = 1, date_valid=now(), fk_user_valid=$userid"; $sql .= " WHERE rowid = $this->id AND fk_statut = 0 ;"; - + if ($this->db->query($sql) ) { /* - * Set generates files readonly - * - */ + * Set generates files readonly + */ umask(0); $file = $outputdir . "/$this->ref/$this->ref.tex"; if (is_writeable($file)) @@ -232,15 +242,15 @@ class Fichinter { chmod($filepdf, 0444); } - + /* - * Notify - */ + * Notify + */ $mesg = "La fiche d'intervention ".$this->ref." a été validée.\n"; - + $notify = New Notify($this->db); $notify->send($action_notify, $this->societe_id, $mesg, "ficheinter", $this->id, $filepdf); - + return 1; } else @@ -248,30 +258,49 @@ class Fichinter print $this->db->error() . ' in ' . $sql; return -1; } - + } - /* - * \brief Charge la liste des clients depuis la base - */ - function fetch_client() + /* + * \brief Charge la liste des clients depuis la base + */ + function fetch_client() { - $client = new Societe($this->db); - $client->fetch($this->societe_id); - $this->client = $client; + $client = new Societe($this->db); + $client->fetch($this->societe_id); + $this->client = $client; } - /* - * \brief Charge les infos du projet depuis la base - * - */ - function fetch_projet() + /* + * \brief Charge les infos du projet depuis la base + * + */ + function fetch_projet() { - $projet = new Project($this->db); - $projet->fetch($this->projet_id); - $this->projet = $projet->title; + $projet = new Project($this->db); + $projet->fetch($this->projet_id); + $this->projet = $projet->title; } - -} + + + /** + * \brief Retourne le libellé du statut de l'intervantion + * \return string Libellé + */ + function getLibStatut() + { + return $this->LibStatut($this->statut); + } + + /** + * \brief Renvoi le libellé d'un statut donné + * \param statut id statut + * \return string Libellé + */ + function LibStatut($statut) + { + return $this->statuts[$statut]; + } +} ?> diff --git a/htdocs/fichinter/index.php b/htdocs/fichinter/index.php index a358f791905..e58b60df067 100644 --- a/htdocs/fichinter/index.php +++ b/htdocs/fichinter/index.php @@ -28,7 +28,8 @@ */ require("./pre.inc.php"); -require("../contact.class.php"); +require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); +require_once(DOL_DOCUMENT_ROOT."/fichinter/fichinter.class.php"); $langs->load("interventions"); @@ -69,48 +70,49 @@ $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit( $limit + 1 ,$offset); $result=$db->query($sql); if ($result) { - $num = $db->num_rows($result); - print_barre_liste($langs->trans("ListOfInterventions"), $page, "index.php","&socid=$socid",$sortfield,$sortorder,'',$num); + $fichinter_static=new Fichinter($db); - $i = 0; - print ''; - print ""; - print_liste_field_titre($langs->trans("Ref"),"index.php","f.ref","","&socid=$socid",'width="15%"',$sortfield); - print_liste_field_titre($langs->trans("Company"),"index.php","s.nom","","&socid=$socid",'',$sortfield); - print ''; - print_liste_field_titre($langs->trans("Date"),"index.php","f.datei","","&socid=$socid",'align="center"',$sortfield); - print ''; - print ''; - print "\n"; - $var=True; - $total = 0; - while ($i < $num) + $num = $db->num_rows($result); + print_barre_liste($langs->trans("ListOfInterventions"), $page, "index.php","&socid=$socid",$sortfield,$sortorder,'',$num); + + $i = 0; + print '
'.$langs->trans("Description").''.$langs->trans("Duration").''.$langs->trans("Status").'
'; + print ""; + print_liste_field_titre($langs->trans("Ref"),"index.php","f.ref","","&socid=$socid",'width="15%"',$sortfield); + print_liste_field_titre($langs->trans("Company"),"index.php","s.nom","","&socid=$socid",'',$sortfield); + print ''; + print_liste_field_titre($langs->trans("Date"),"index.php","f.datei","","&socid=$socid",'align="center"',$sortfield); + print ''; + print ''; + print "\n"; + $var=True; + $total = 0; + while ($i < $num) { - $objp = $db->fetch_object($result); - $var=!$var; - print ""; - print "\n"; + $objp = $db->fetch_object($result); + $var=!$var; + print ""; + print "\n"; + print '\n"; + print ''; + print '\n"; + print ''; + print ''; - print '\n"; - print ''; - print '\n"; - print ''; - print ''; - - print "\n"; - $total += $objp->duree; - $i++; + print "\n"; + $total += $objp->duree; + $i++; } - print ''; - print ""; - print ""; + print ''; + print ''; + print ''; - print "
'.$langs->trans("Description").''.$langs->trans("Duration").''.$langs->trans("Status").'
fichid\">".img_object($langs->trans("Show"),"task").' '.$objp->ref."
fichid\">".img_object($langs->trans("Show"),"task").' '.$objp->ref."'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($objp->nom,44)."'.nl2br($objp->note).''.dolibarr_print_date($objp->dp)."'.price($objp->duree).''.$fichinter_static->LibStatut($objp->fk_statut).''.img_object($langs->trans("ShowCompany"),"company").' '.$objp->nom."'.nl2br($objp->note).''.dolibarr_print_date($objp->dp)."'.price($objp->duree).''.$objp->fk_statut.'
'.$langs->trans("Total").'".price($total)."
'.$langs->trans("Total").''.price($total).'
"; - $db->free($result); + print ''; + $db->free($result); } else { - dolibarr_print_error($db); + dolibarr_print_error($db); } $db->close(); diff --git a/htdocs/fichinter/rapport.php b/htdocs/fichinter/rapport.php index cdcd7b9c65e..1566d5503ab 100644 --- a/htdocs/fichinter/rapport.php +++ b/htdocs/fichinter/rapport.php @@ -20,8 +20,9 @@ * $Source$ * */ + require("./pre.inc.php"); -require("../contact.class.php"); +require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); if ($user->societe_id > 0) { @@ -29,6 +30,7 @@ if ($user->societe_id > 0) } llxHeader(); + /* * Liste *