diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 98db9ccc3f8..59ed3acd46e 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -71,7 +71,7 @@ $NBLINES=4; if ($_POST["action"] == 'classin') { $facture = new Facture($db); - $facture->fetch($_POST["facid"]); + $facture->fetch($_GET["facid"]); $facture->classin($_POST["projetid"]); } @@ -884,7 +884,7 @@ else */ if ($_GET["action"] == 'canceled') { - $html->form_confirm($_SERVER["PHP_SELF"]."?facid=$fac->id","Classer la facture à l'état 'Abandonnée'","La totalité du paiement de cette facture n'a pas été réalisée. Etes-vous sûr de vouloir abandonner définitivement cette facture ?","confirm_canceled"); + $html->form_confirm($_SERVER["PHP_SELF"]."?facid=$fac->id",$langs->trans("CancelBill"),$langs->trans("ConfirmCancelBill"),"confirm_canceled"); print '
'; } @@ -916,25 +916,31 @@ else print ""; print ''; - if ($conf->projet->enabled) - { - $langs->load("projects"); - print ''.$langs->trans("Project").''; - if ($fac->projetid > 0) - { - $projet = New Project($db); - $projet->fetch($fac->projetid); - print ''.$projet->title.''; - } - else - { - print ''.$langs->trans("ClassifyBill").''; - } - print " "; + + // Projet + if ($conf->projet->enabled) + { + $langs->load("projects"); + print ''; + print ''; + if ($_GET["action"] != "classer") print ''; + print '
'; + print $langs->trans("Project"); + print ''.img_edit($langs->trans("SetProject")).'
'; + print ''; + if ($_GET["action"] == "classer") + { + $html->form_project("facture.php?facid=$fac->id",$fac->fk_soc,$fac->projetid,"projetid"); + } + else + { + $html->form_project("facture.php?facid=$fac->id",$fac->fk_soc,$fac->projetid,"none"); + } + print ""; } else { - print ' '; - print " "; + print '  '; } + print ''; /* @@ -1456,27 +1462,6 @@ else print ""; - /* - * Choix d'un projet - */ - if ($_GET["action"] == 'classer') - { - print "

id\">\n"; - print ''; - print ''; - print ''; - - print '"; - - print '
'.$langs->trans("Project").''; - - $proj = new Project($db); - $html->select_array("projetid",$proj->liste_array($soc->id)); - - print "

'; - } - - /* * Affiche formulaire mail */ diff --git a/htdocs/contrat/contrat.class.php b/htdocs/contrat/contrat.class.php index 42cbf73fa27..cb2402dd3cd 100644 --- a/htdocs/contrat/contrat.class.php +++ b/htdocs/contrat/contrat.class.php @@ -51,7 +51,9 @@ class Contrat var $commercial_signature_id; var $commercial_suivi_id; - + + var $fk_projet; + var $statuts=array(); @@ -274,11 +276,12 @@ class Contrat */ function fetch($id) { - $sql = "SELECT rowid, statut, fk_soc, ".$this->db->pdate("mise_en_service")." as datemise"; - $sql .= ", fk_user_mise_en_service, ".$this->db->pdate("date_contrat")." as datecontrat"; - $sql .= ", fk_user_author"; - $sql .= ", fk_commercial_signature, fk_commercial_suivi "; - $sql .= " FROM ".MAIN_DB_PREFIX."contrat WHERE rowid = $id"; + $sql = "SELECT rowid, statut, fk_soc, ".$this->db->pdate("mise_en_service")." as datemise,"; + $sql.= " fk_user_mise_en_service, ".$this->db->pdate("date_contrat")." as datecontrat,"; + $sql.= " fk_user_author,"; + $sql.= " fk_projet,"; + $sql.= " fk_commercial_signature, fk_commercial_suivi "; + $sql.= " FROM ".MAIN_DB_PREFIX."contrat WHERE rowid = $id"; $resql = $this->db->query($sql) ; @@ -302,6 +305,8 @@ class Contrat $this->user_service->id = $result["fk_user_mise_en_service"]; $this->user_cloture->id = $result["fk_user_cloture"]; + + $this->fk_projet = $result["fk_projet"]; $this->societe->fetch($result["fk_soc"]); @@ -541,6 +546,29 @@ class Contrat } + /** + * \brief Classe le contrat dans un projet + * \param projid Id du projet dans lequel classer le contrat + */ + function classin($projid) + { + $sql = "UPDATE ".MAIN_DB_PREFIX."contrat"; + if ($projid) $sql.= " SET fk_projet = $projid"; + else $sql.= " SET fk_projet = NULL"; + $sql.= " WHERE rowid = ".$this->id; + + if ($this->db->query($sql)) + { + return 1; + } + else + { + dolibarr_print_error($this->db); + return -1; + } + } + + /** * \brief Retourne le libellé du statut du contrat * \return string Libellé @@ -612,6 +640,41 @@ class Contrat dolibarr_print_error($this->db); } } - + + + /** + * \brief Récupère les lignes de detail du contrat + * \param statut Statut des lignes detail à récupérer + * \return array Tableau des lignes de details + */ + function array_detail($statut=-1) + { + $tab=array(); + + $sql = "SELECT cd.rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd"; + $sql.= " WHERE fk_contrat =".$this->id; + if ($statut >= 0) $sql.= " AND statut = '$statut'"; + + $resql=$this->db->query($sql); + if ($resql) + { + $num=$this->db->num_rows($result); + $i=0; + while ($i < $num) + { + $obj = $this->db->fetch_object($result); + $tab[$i]=$obj->rowid; + $i++; + } + return $tab; + } + else + { + $this->error=$this->db->error(); + return -1; + } + } + } ?> diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index d6288c5bc8a..6d3432c0927 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -534,16 +534,21 @@ else // Projet if ($conf->projet->enabled) { - print ''.$langs->trans("Project").''; - if ($contrat->projet_id > 0) + $langs->load("projects"); + print ''; + print ''; + if ($_GET["action"] != "classer") print ''; + print '
'; + print $langs->trans("Project"); + print ''.img_edit($langs->trans("SetProject")).'
'; + print ''; + if ($_GET["action"] == "classer") { - $projet = New Project($db); - $projet->fetch($contrat->projet_id); - print ''.$projet->title.''; + $html->form_project("fiche.php?id=$id",$contrat->fk_soc,$contrat->fk_projet,"projetid"); } else { - print 'Classer le contrat'; + $html->form_project("fiche.php?id=$id",$contrat->fk_soc,$contrat->fk_projet,"none"); } print ""; } @@ -831,9 +836,8 @@ else print ''.$langs->trans("Valid").''; } - // \todo Mettre bouton cloturer que si tous les services sont clos - $numclos=$num; - if ($contrat->statut == 1 && $num == $numclos) + $numclos=$contrat->array_detail(5); // Tableau des lignes au statut clos + if ($contrat->statut == 1 && $num == sizeof($numclos)) { print ''.$langs->trans("Close").''; } @@ -846,29 +850,10 @@ else print ""; } - /* - * - * - */ - if ($_GET["action"] == 'classer') - { - $langs->load("project"); - print '

'; - print ''; - print ''; - print '"; - print '
'.$langs->trans("Project").''; - - $proj = new Project($db); - $html->select_array("projetid",$proj->liste_array($contrat->soc_id)); - - print "
'; - } - } else { - /* Contrat non trouvée */ + // Contrat non trouvé print "Contrat inexistant ou accés refusé"; } } diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 770c2d3c43c..9e8b678387e 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -530,22 +530,24 @@ class Facture } /** - * \brief Classe la facture - * \param cat_id id de la catégorie dans laquelle classer la facture - * - */ - function classin($cat_id) + * \brief Classe la facture dans un projet + * \param projid Id du projet dans lequel classer la facture + */ + function classin($projid) { - $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET fk_projet = $cat_id"; - $sql .= " WHERE rowid = $this->id;"; + $sql = "UPDATE ".MAIN_DB_PREFIX."facture"; + if ($projid) $sql.= " SET fk_projet = $projid"; + else $sql.= " SET fk_projet = NULL"; + $sql.= " WHERE rowid = ".$this->id; - if ($this->db->query($sql) ) + if ($this->db->query($sql)) { return 1; } else { dolibarr_print_error($this->db); + return -1; } } diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index c7c7222b320..936bb1f7d00 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -398,14 +398,11 @@ class Form */ function select_projects($socid='', $selected='', $htmlname='projectid') { - $socid=intVal($socid); - if (empty($socid)) - return; - // On recherche les societes + // On recherche les projets $sql = 'SELECT p.rowid, p.title FROM '; - $sql .= MAIN_DB_PREFIX .'projet as p'; - $sql .= ' WHERE fk_soc='.$socid; - $sql .= ' ORDER BY p.title ASC'; + $sql.= MAIN_DB_PREFIX .'projet as p'; + $sql.= " WHERE fk_soc='".$socid."'"; + $sql.= " ORDER BY p.title ASC"; $result=$this->db->query($sql); if ($result) @@ -781,6 +778,40 @@ class Form } + /** + * \brief Affiche formulaire de selection de projet + * \param page Page + * \param socid Id societe + * \param selected Id projet présélectionné + * \param htmlname Nom du formulaire select + */ + function form_project($page, $socid, $selected='', $htmlname='projectid') + { + global $langs; + $langs->load("project"); + if ($htmlname != "none") + { + print '
'; + print ''; + print ''; + print ''; + print ''; + print '
'; + $this->select_projects($soc_id,$selected,$htmlname); + print '
'; + } + else + { + if ($selected) { + $projet = New Project($this->db); + $projet->fetch($selected); + print ''.$projet->title.''; + } else { + print " "; + } + } + } + /** * \brief Retourne la liste des devies, dans la langue de l'utilisateur * \param selected code devise pré-sélectionnée diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index 8b2eb0f6561..7df2a04cc01 100755 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -9,4 +9,5 @@ ConfirmDeleteAProject=Are you sure you want to delete this project ? LastProjects=Last %s projects AllProjects=All projects ShowProject=Show project +SetProject=Set project NoProject=No project defined \ No newline at end of file diff --git a/htdocs/langs/fr_FR/projects.lang b/htdocs/langs/fr_FR/projects.lang index d016b1b4563..99cc7ada49c 100755 --- a/htdocs/langs/fr_FR/projects.lang +++ b/htdocs/langs/fr_FR/projects.lang @@ -9,4 +9,5 @@ ConfirmDeleteAProject= LastProjects=Les %s derniers projets AllProjects=Tous les projets ShowProject=Afficher projet +SetProject=Définir projet NoProject=Aucun projet défini \ No newline at end of file diff --git a/htdocs/soc.php b/htdocs/soc.php index 22cad0c3818..568e50fe0a0 100644 --- a/htdocs/soc.php +++ b/htdocs/soc.php @@ -572,7 +572,7 @@ else // RIB print ''; - print '
'; + print '
'; print $langs->trans('RIB'); print ''; print ''.img_edit().''; @@ -584,7 +584,7 @@ else // Maison mère print '
'; - print '
'; + print '
'; print $langs->trans('ParentCompany'); print ''; print ''.img_edit() .''; @@ -604,7 +604,7 @@ else // Commerciaux print '
'; - print '
'; + print '
'; print $langs->trans('SalesRepresentatives'); print ''; print ''.img_edit().'';