diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 11ee150b581..4dfc9fbe8bb 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -624,7 +624,7 @@ if ($_REQUEST['action'] == 'builddoc' && $user->rights->propale->creer) $propal->fetch($_GET['propalid']); if ($_REQUEST['model']) { - $propal->set_pdf_model($user, $_REQUEST['model']); + $propal->setDocModel($user, $_REQUEST['model']); } if ($_REQUEST['lang_id']) diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php index 3391afeec00..f9ededf9340 100644 --- a/htdocs/commande/commande.class.php +++ b/htdocs/commande/commande.class.php @@ -149,47 +149,54 @@ class Commande extends CommonObject } - /** - * \brief Renvoie la référence de commande suivante non utilisée en fonction du module - * de numérotation actif défini dans COMMANDE_ADDON - * \param soc objet societe - * \return string reference libre pour la commande - */ - function getNextNumRef($soc) - { - global $db, $langs, $conf; - $langs->load("order"); + /** + * \brief Renvoie la référence de commande suivante non utilisée en fonction du module + * de numérotation actif défini dans COMMANDE_ADDON + * \param soc objet societe + * \return string reference libre pour la commande + */ + function getNextNumRef($soc) + { + global $db, $langs, $conf; + $langs->load("order"); - $dir = DOL_DOCUMENT_ROOT . "/includes/modules/commande"; + $dir = DOL_DOCUMENT_ROOT . "/includes/modules/commande"; - if (defined("COMMANDE_ADDON") && COMMANDE_ADDON) - { - $file = COMMANDE_ADDON.".php"; + if (! empty($conf->global->COMMANDE_ADDON)) + { + $file = $conf->global->COMMANDE_ADDON.".php"; - // Chargement de la classe de numérotation - $classname = $conf->global->COMMANDE_ADDON; - require_once($dir.'/'.$file); + // Chargement de la classe de numérotation + $classname = $conf->global->COMMANDE_ADDON; + $result=include_once($dir.'/'.$file); + if ($result) + { + $obj = new $classname(); + $numref = ""; + $numref = $obj->getNextValue($soc,$this); - $obj = new $classname(); - $numref = ""; - $numref = $obj->getNextValue($soc,$this); - - if ( $numref != "") - { - return $numref; - } - else - { - dolibarr_print_error($db,"Commande::getNextNumRef ".$obj->error); - return ""; - } - } - else - { - print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_ADDON_NotDefined"); - return ""; - } - } + if ( $numref != "") + { + return $numref; + } + else + { + dolibarr_print_error($db,"Commande::getNextNumRef ".$obj->error); + return ""; + } + } + else + { + print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_ADDON_NotDefined"); + return ""; + } + } + else + { + print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_ADDON_NotDefined"); + return ""; + } + } /** @@ -1086,31 +1093,6 @@ class Commande extends CommonObject } - /** - * \brief Positionne modele derniere generation - * \param user Objet use qui modifie - * \param modelpdf Nom du modele - */ - function set_pdf_model($user, $modelpdf) - { - if ($user->rights->commande->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."commande SET model_pdf = '$modelpdf'"; - $sql.= " WHERE rowid = ".$this->id; - - if ($this->db->query($sql) ) - { - $this->modelpdf=$modelpdf; - return 1; - } - else - { - dolibarr_print_error($this->db); - return 0; - } - } - } - /** * \brief Reinitialise le tableau lignes * \param only_product Ne renvoie que ligne liées à des produits physiques prédéfinis diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 5cf04aaeca1..b1623cf9493 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2004-2008 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2008 Regis Houssin * Copyright (C) 2006 Andre Cianfarani @@ -63,15 +63,14 @@ if ($user->societe_id >0 && isset($_GET["id"]) && $_GET["id"]>0) } } - - // Recuperation de l'id de projet $projetid = 0; if ($_GET["projetid"]) { - $projetid = $_GET["projetid"]; + $projetid = $_GET["projetid"]; } + /******************************************************************************/ /* Actions */ /******************************************************************************/ @@ -503,37 +502,38 @@ if ($_GET['action'] == 'down' && $user->rights->commande->creer) exit; } -if ($_REQUEST['action'] == 'builddoc') // En get ou en post +if ($_REQUEST['action'] == 'builddoc') // In get or post { - /* - * Generation de la commande - * definit dans /includes/modules/commande/modules_commande.php - */ + /* + * Generate order document + * define into /includes/modules/commande/modules_commande.php + */ - // Sauvegarde le dernier modele choisi pour generer un document - $commande = new Commande($db, 0, $_REQUEST['id']); - $commande->fetch($_REQUEST['id']); - if ($_REQUEST['model']) - { - $commande->set_pdf_model($user, $_REQUEST['model']); - } + // Sauvegarde le dernier modele choisi pour generer un document + $commande = new Commande($db, 0, $_REQUEST['id']); + $commande->fetch($_REQUEST['id']); + if ($_REQUEST['model']) + { + $commande->setDocModel($user, $_REQUEST['model']); + } - if ($_REQUEST['lang_id']) - { - $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf); - $outputlangs->setDefaultLang($_REQUEST['lang_id']); - } - $result=commande_pdf_create($db, $commande->id,$commande->modelpdf,$outputlangs); - if ($result <= 0) - { - dolibarr_print_error($db,$result); - exit; - } - else - { - Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$commande->id.'#builddoc'); - exit; - } + if ($_REQUEST['lang_id']) + { + $outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf); + $outputlangs->setDefaultLang($_REQUEST['lang_id']); + } + + $result=commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); + if ($result <= 0) + { + dolibarr_print_error($db,$result); + exit; + } + else + { + Header ('Location: '.$_SERVER["PHP_SELF"].'?id='.$commande->id.'#builddoc'); + exit; + } } // Efface les fichiers diff --git a/htdocs/commonobject.class.php b/htdocs/commonobject.class.php index e45d0c32851..10352d1f11b 100644 --- a/htdocs/commonobject.class.php +++ b/htdocs/commonobject.class.php @@ -593,6 +593,40 @@ class CommonObject } } + + /** + * \brief Set last model used by doc generator + * \param user User object that make change + * \param modelpdf Modele name + * \return int <0 if KO, >0 if OK + */ + function setDocModel($user, $modelpdf) + { + if (! $this->table_element) + { + dolibarr_syslog("CommonObject::setDocModel was called on objet with property table_element not defined"); + return -1; + } + + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql.= " SET model_pdf = '".$modelpdf."'"; + $sql.= " WHERE rowid = ".$this->id; + // if ($this->element == 'facture') $sql.= " AND fk_statut < 2"; + // if ($this->element == 'propal') $sql.= " AND fk_statut = 0"; + + dolibarr_syslog("CommonObject::setDocModel sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $this->modelpdf=$modelpdf; + return 1; + } + else + { + dolibarr_print_error($this->db); + return 0; + } + } } ?> diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 835a6f05fb0..5aba210fd46 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1134,7 +1134,7 @@ if ($_REQUEST['action'] == 'builddoc') // En get ou en post if ($_REQUEST['model']) { - $fac->set_pdf_model($user, $_REQUEST['model']); + $fac->setDocModel($user, $_REQUEST['model']); } if ($_REQUEST['lang_id']) diff --git a/htdocs/expedition/expedition.class.php b/htdocs/expedition/expedition.class.php index c4626c99134..e92f0df2663 100644 --- a/htdocs/expedition/expedition.class.php +++ b/htdocs/expedition/expedition.class.php @@ -543,32 +543,6 @@ class Expedition extends CommonObject } - /** - * \brief Positionne modele derniere generation - * \param user Objet use qui modifie - * \param modelpdf Nom du modele - */ - function set_pdf_model($user, $modelpdf) - { - if ($user->rights->expedition->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."expedition SET model_pdf = '$modelpdf'"; - $sql.= " WHERE rowid = ".$this->id; - - if ($this->db->query($sql) ) - { - $this->modelpdf=$modelpdf; - return 1; - } - else - { - dolibarr_print_error($this->db); - return 0; - } - } - } - - /* * Lit le document associé * diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php index 5b50e5bdfe0..432b4a04702 100644 --- a/htdocs/expedition/fiche.php +++ b/htdocs/expedition/fiche.php @@ -153,7 +153,7 @@ if ($_REQUEST['action'] == 'builddoc') // En get ou en post if ($_REQUEST['model']) { - $expedition->set_pdf_model($user, $_REQUEST['model']); + $expedition->setDocModel($user, $_REQUEST['model']); } if ($_REQUEST['lang_id']) diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 814aaad391a..66c779dfd9c 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -1222,31 +1222,6 @@ class Facture extends CommonObject } - /** - * \brief Positionne modele derniere generation - * \param user Objet use qui modifie - * \param modelpdf Nom du modele - */ - function set_pdf_model($user, $modelpdf) - { - if ($user->rights->facture->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."facture SET model_pdf = '$modelpdf'"; - $sql .= " WHERE rowid = $this->id AND fk_statut < 2 ;"; - - if ($this->db->query($sql) ) - { - $this->modelpdf=$modelpdf; - return 1; - } - else - { - dolibarr_print_error($this->db); - return 0; - } - } - } - /** \brief Ajoute une ligne dans le tableau products \param idproduct Id du produit a ajouter diff --git a/htdocs/fichinter/fichinter.class.php b/htdocs/fichinter/fichinter.class.php index 784fc2a788b..012c9970f91 100644 --- a/htdocs/fichinter/fichinter.class.php +++ b/htdocs/fichinter/fichinter.class.php @@ -286,32 +286,6 @@ class Fichinter extends CommonObject } } - /** - * \brief Positionne modele derniere generation - * \param user Objet use qui modifie - * \param modelpdf Nom du modele - */ - function set_pdf_model($user, $modelpdf) - { - if ($user->rights->facture->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter SET model_pdf = '$modelpdf'"; - $sql .= " WHERE rowid = ".$this->id; - - $resql=$this->db->query($sql); - if ($resql) - { - $this->modelpdf=$modelpdf; - return 1; - } - else - { - dolibarr_print_error($this->db); - return 0; - } - } - } - /** * \brief Verifie si la ref n'est pas deja utilisee * \param soc objet societe diff --git a/htdocs/fourn/commande/fiche.php b/htdocs/fourn/commande/fiche.php index 613879f7538..a5e505e909d 100644 --- a/htdocs/fourn/commande/fiche.php +++ b/htdocs/fourn/commande/fiche.php @@ -342,7 +342,7 @@ if ($_REQUEST['action'] == 'builddoc') // En get ou en post $commande->fetch($_REQUEST['id']); if ($_REQUEST['model']) { - $commande->set_pdf_model($user, $_REQUEST['model']); + $commande->setDocModel($user, $_REQUEST['model']); } if ($_REQUEST['lang_id']) diff --git a/htdocs/fourn/fournisseur.commande.class.php b/htdocs/fourn/fournisseur.commande.class.php index a4db5a53dbf..48637f41530 100644 --- a/htdocs/fourn/fournisseur.commande.class.php +++ b/htdocs/fourn/fournisseur.commande.class.php @@ -975,30 +975,7 @@ class CommandeFournisseur extends Commande return -1; } } - /** - * \brief Positionne modele derniere generation - * \param user Objet use qui modifie - * \param modelpdf Nom du modele - */ - function set_pdf_model($user, $modelpdf) - { - if ($user->rights->fournisseur->commande->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET model_pdf = '".$modelpdf."'"; - $sql .= " WHERE rowid = ".$this->id." AND fk_statut = 0 ;"; - - if ($this->db->query($sql) ) - { - $this->modelpdf=$modelpdf; - return 1; - } - else - { - dolibarr_print_error($this->db); - return 0; - } - } - } + /** * * diff --git a/htdocs/livraison/fiche.php b/htdocs/livraison/fiche.php index 5544217ea20..574053b954d 100644 --- a/htdocs/livraison/fiche.php +++ b/htdocs/livraison/fiche.php @@ -136,12 +136,12 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes') */ if ($_REQUEST['action'] == 'builddoc') // En get ou en post { - $livraision = new Livraison($db, 0, $_REQUEST['id']); - $livraision->fetch($_REQUEST['id']); + $delivery = new Livraison($db, 0, $_REQUEST['id']); + $delivery->fetch($_REQUEST['id']); if ($_REQUEST['model']) { - $livraision->set_pdf_model($user, $_REQUEST['model']); + $delivery->setDocModel($user, $_REQUEST['model']); } if ($_REQUEST['lang_id']) diff --git a/htdocs/livraison/livraison.class.php b/htdocs/livraison/livraison.class.php index c624f67431b..b81990e2eb3 100644 --- a/htdocs/livraison/livraison.class.php +++ b/htdocs/livraison/livraison.class.php @@ -697,34 +697,10 @@ class Livraison extends CommonObject } } - /** - * \brief Positionne modele derniere generation - * \param user Objet use qui modifie - * \param modelpdf Nom du modele - */ - function set_pdf_model($user, $modelpdf) - { - if ($user->rights->expedition->livraison->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."livraison SET model_pdf = '$modelpdf'"; - $sql .= " WHERE rowid = $this->id ;"; - - if ($this->db->query($sql) ) - { - $this->modelpdf=$modelpdf; - return 1; - } - else - { - dolibarr_print_error($this->db); - return 0; - } - } - } - } + /** \class LivraisonLigne \brief Classe de gestion des lignes de bons de livraison diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index eb46772bd91..eef0c7065cb 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -1194,32 +1194,6 @@ class Propal extends CommonObject } - /** - * \brief Positionne modele derniere generation - * \param user Objet use qui modifie - * \param modelpdf Nom du modele - */ - function set_pdf_model($user, $modelpdf) - { - if ($user->rights->propale->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; - $sql.= " SET model_pdf = '".$modelpdf."'"; - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; - - if ($this->db->query($sql)) - { - $this->modelpdf=$modelpdf; - return 1; - } - else - { - dolibarr_print_error($this->db); - return 0; - } - } - } - /** * \brief Cloture de la proposition commerciale * \param user Utilisateur qui cloture