Qual: Mutualize some code
This commit is contained in:
parent
72d107a5d0
commit
f9d4f6de52
@ -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'])
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
||||
* Copyright (C) 2005-2008 Regis Houssin <regis@dolibarr.fr>
|
||||
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@ -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'])
|
||||
|
||||
@ -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é
|
||||
*
|
||||
|
||||
@ -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'])
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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'])
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
||||
@ -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'])
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user