Skip to content

Commit

Permalink
Qual: Mutualize some code
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Feb 24, 2008
1 parent 72d107a commit f9d4f6d
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 253 deletions.
2 changes: 1 addition & 1 deletion htdocs/comm/propal.php
Expand Up @@ -624,7 +624,7 @@
$propal->fetch($_GET['propalid']);
if ($_REQUEST['model'])
{
$propal->set_pdf_model($user, $_REQUEST['model']);
$propal->setDocModel($user, $_REQUEST['model']);
}

if ($_REQUEST['lang_id'])
Expand Down
106 changes: 44 additions & 62 deletions htdocs/commande/commande.class.php
Expand Up @@ -149,47 +149,54 @@ function create_from_propale($user, $propale_id)
}


/**
* \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";
/**
* \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");

if (defined("COMMANDE_ADDON") && COMMANDE_ADDON)
{
$file = COMMANDE_ADDON.".php";
$dir = DOL_DOCUMENT_ROOT . "/includes/modules/commande";

// Chargement de la classe de numérotation
$classname = $conf->global->COMMANDE_ADDON;
require_once($dir.'/'.$file);
if (! empty($conf->global->COMMANDE_ADDON))
{
$file = $conf->global->COMMANDE_ADDON.".php";

$obj = new $classname();
$numref = "";
$numref = $obj->getNextValue($soc,$this);
// 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);

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 "";
}
}


/**
Expand Down Expand Up @@ -1086,31 +1093,6 @@ function insert_discount($idremise)
}


/**
* \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
Expand Down
64 changes: 32 additions & 32 deletions htdocs/commande/fiche.php
@@ -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>
Expand Down Expand Up @@ -63,15 +63,14 @@
}
}



// Recuperation de l'id de projet
$projetid = 0;
if ($_GET["projetid"])
{
$projetid = $_GET["projetid"];
$projetid = $_GET["projetid"];
}


/******************************************************************************/
/* Actions */
/******************************************************************************/
Expand Down Expand Up @@ -503,37 +502,38 @@
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->setDocModel($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->set_pdf_model($user, $_REQUEST['model']);
}
if ($_REQUEST['lang_id'])
{
$outputlangs = new Translate(DOL_DOCUMENT_ROOT ."/langs",$conf);
$outputlangs->setDefaultLang($_REQUEST['lang_id']);
}

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;
}
$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
Expand Down
34 changes: 34 additions & 0 deletions htdocs/commonobject.class.php
Expand Up @@ -593,6 +593,40 @@ function setProject($projid)
}
}


/**
* \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;
}
}
}

?>
2 changes: 1 addition & 1 deletion htdocs/compta/facture.php
Expand Up @@ -1134,7 +1134,7 @@

if ($_REQUEST['model'])
{
$fac->set_pdf_model($user, $_REQUEST['model']);
$fac->setDocModel($user, $_REQUEST['model']);
}

if ($_REQUEST['lang_id'])
Expand Down
26 changes: 0 additions & 26 deletions htdocs/expedition/expedition.class.php
Expand Up @@ -543,32 +543,6 @@ function delete()
}


/**
* \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é
*
Expand Down
2 changes: 1 addition & 1 deletion htdocs/expedition/fiche.php
Expand Up @@ -153,7 +153,7 @@

if ($_REQUEST['model'])
{
$expedition->set_pdf_model($user, $_REQUEST['model']);
$expedition->setDocModel($user, $_REQUEST['model']);
}

if ($_REQUEST['lang_id'])
Expand Down
25 changes: 0 additions & 25 deletions htdocs/facture.class.php
Expand Up @@ -1222,31 +1222,6 @@ function set_draft($userid)
}


/**
* \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
Expand Down
26 changes: 0 additions & 26 deletions htdocs/fichinter/fichinter.class.php
Expand Up @@ -286,32 +286,6 @@ function LibStatut($statut,$mode=0)
}
}

/**
* \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
Expand Down
2 changes: 1 addition & 1 deletion htdocs/fourn/commande/fiche.php
Expand Up @@ -342,7 +342,7 @@
$commande->fetch($_REQUEST['id']);
if ($_REQUEST['model'])
{
$commande->set_pdf_model($user, $_REQUEST['model']);
$commande->setDocModel($user, $_REQUEST['model']);
}

if ($_REQUEST['lang_id'])
Expand Down

0 comments on commit f9d4f6d

Please sign in to comment.