2004-12-28 18:14:25 +01:00
|
|
|
|
<?php
|
|
|
|
|
|
/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2007-09-13 20:10:51 +02:00
|
|
|
|
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
|
2004-12-28 18:14:25 +01:00
|
|
|
|
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
2006-02-08 15:32:08 +01:00
|
|
|
|
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
2004-12-28 18:14:25 +01:00
|
|
|
|
*
|
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
* or see http://www.gnu.org/
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2005-08-23 21:31:25 +02:00
|
|
|
|
/**
|
2006-11-08 00:39:29 +01:00
|
|
|
|
\file htdocs/includes/modules/commande/modules_commande.php
|
|
|
|
|
|
\ingroup commande
|
|
|
|
|
|
\brief Fichier contenant la classe m<EFBFBD>re de generation des commandes en PDF
|
|
|
|
|
|
et la classe m<EFBFBD>re de num<EFBFBD>rotation des commandes
|
2008-04-05 16:18:13 +02:00
|
|
|
|
\version $Id$
|
2004-12-28 18:14:25 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2009-01-28 16:09:37 +01:00
|
|
|
|
require_once(DOL_DOCUMENT_ROOT.'/lib/pdf.lib.php');
|
2007-07-31 01:22:06 +02:00
|
|
|
|
require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php');
|
2006-11-11 02:49:14 +01:00
|
|
|
|
require_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); // requis car utilise par les classes qui heritent
|
2007-10-03 16:19:10 +02:00
|
|
|
|
require_once(DOL_DOCUMENT_ROOT.'/discount.class.php');
|
2004-12-28 18:14:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
2005-08-23 21:31:25 +02:00
|
|
|
|
/**
|
2006-11-11 02:49:14 +01:00
|
|
|
|
\class ModelePDFCommandes
|
|
|
|
|
|
\brief Classe m<EFBFBD>re des mod<EFBFBD>les de commandes
|
2004-12-28 18:14:25 +01:00
|
|
|
|
*/
|
|
|
|
|
|
class ModelePDFCommandes extends FPDF
|
|
|
|
|
|
{
|
|
|
|
|
|
var $error='';
|
|
|
|
|
|
|
2006-11-11 02:49:14 +01:00
|
|
|
|
/**
|
|
|
|
|
|
* \brief Renvoi le dernier message d'erreur de cr<EFBFBD>ation de PDF de commande
|
2004-12-28 18:14:25 +01:00
|
|
|
|
*/
|
|
|
|
|
|
function pdferror()
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->error;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-11-11 02:49:14 +01:00
|
|
|
|
/**
|
2005-08-23 21:31:25 +02:00
|
|
|
|
* \brief Renvoi la liste des mod<EFBFBD>les actifs
|
2006-05-06 01:57:38 +02:00
|
|
|
|
* \return array Tableau des modeles (cle=id, valeur=libelle)
|
2005-08-23 21:31:25 +02:00
|
|
|
|
*/
|
2006-02-09 09:37:11 +01:00
|
|
|
|
function liste_modeles($db)
|
2005-08-23 21:31:25 +02:00
|
|
|
|
{
|
2006-04-29 00:54:02 +02:00
|
|
|
|
$type='order';
|
2005-08-23 21:31:25 +02:00
|
|
|
|
$liste=array();
|
2006-02-09 09:37:11 +01:00
|
|
|
|
$sql ="SELECT nom as id, nom as lib";
|
2006-04-29 00:54:02 +02:00
|
|
|
|
$sql.=" FROM ".MAIN_DB_PREFIX."document_model";
|
|
|
|
|
|
$sql.=" WHERE type = '".$type."'";
|
2006-11-11 02:49:14 +01:00
|
|
|
|
|
2006-02-09 09:37:11 +01:00
|
|
|
|
$resql = $db->query($sql);
|
|
|
|
|
|
if ($resql)
|
|
|
|
|
|
{
|
|
|
|
|
|
$num = $db->num_rows($resql);
|
|
|
|
|
|
$i = 0;
|
|
|
|
|
|
while ($i < $num)
|
|
|
|
|
|
{
|
|
|
|
|
|
$row = $db->fetch_row($resql);
|
|
|
|
|
|
$liste[$row[0]]=$row[1];
|
|
|
|
|
|
$i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error=$db->error();
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
2005-08-23 21:31:25 +02:00
|
|
|
|
return $liste;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-12-28 18:14:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-08-23 21:31:25 +02:00
|
|
|
|
/**
|
|
|
|
|
|
\class ModeleNumRefCommandes
|
2006-02-09 09:37:11 +01:00
|
|
|
|
\brief Classe m<EFBFBD>re des mod<EFBFBD>les de num<EFBFBD>rotation des r<EFBFBD>f<EFBFBD>rences de commandes
|
2004-12-28 18:14:25 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
class ModeleNumRefCommandes
|
|
|
|
|
|
{
|
|
|
|
|
|
var $error='';
|
|
|
|
|
|
|
2008-09-05 01:44:36 +02:00
|
|
|
|
/** \brief Return if a module can be used or not
|
|
|
|
|
|
* \return boolean true if module can be used
|
|
|
|
|
|
*/
|
|
|
|
|
|
function isEnabled()
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-12-28 18:14:25 +01:00
|
|
|
|
/** \brief Renvoi la description par defaut du modele de num<EFBFBD>rotation
|
|
|
|
|
|
* \return string Texte descripif
|
|
|
|
|
|
*/
|
|
|
|
|
|
function info()
|
|
|
|
|
|
{
|
|
|
|
|
|
global $langs;
|
|
|
|
|
|
$langs->load("orders");
|
|
|
|
|
|
return $langs->trans("NoDescription");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** \brief Renvoi un exemple de num<EFBFBD>rotation
|
|
|
|
|
|
* \return string Example
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getExample()
|
|
|
|
|
|
{
|
|
|
|
|
|
global $langs;
|
|
|
|
|
|
$langs->load("orders");
|
|
|
|
|
|
return $langs->trans("NoExample");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-11-11 21:11:57 +01:00
|
|
|
|
/** \brief Test si les num<EFBFBD>ros d<EFBFBD>j<EFBFBD> en vigueur dans la base ne provoquent pas de
|
|
|
|
|
|
* de conflits qui empechera cette num<EFBFBD>rotation de fonctionner.
|
|
|
|
|
|
* \return boolean false si conflit, true si ok
|
|
|
|
|
|
*/
|
|
|
|
|
|
function canBeActivated()
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2004-12-28 18:14:25 +01:00
|
|
|
|
|
2005-11-11 21:11:57 +01:00
|
|
|
|
/** \brief Renvoi prochaine valeur attribu<EFBFBD>e
|
|
|
|
|
|
* \return string Valeur
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getNextValue()
|
|
|
|
|
|
{
|
|
|
|
|
|
global $langs;
|
|
|
|
|
|
return $langs->trans("NotAvailable");
|
|
|
|
|
|
}
|
2006-11-11 02:49:14 +01:00
|
|
|
|
|
2007-09-12 00:01:18 +02:00
|
|
|
|
/** \brief Renvoi version du module numerotation
|
|
|
|
|
|
* \return string Valeur
|
|
|
|
|
|
*/
|
|
|
|
|
|
function getVersion()
|
|
|
|
|
|
{
|
|
|
|
|
|
global $langs;
|
|
|
|
|
|
$langs->load("admin");
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->version == 'development') return $langs->trans("VersionDevelopment");
|
|
|
|
|
|
if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
|
|
|
|
|
|
if ($this->version == 'dolibarr') return DOL_VERSION;
|
|
|
|
|
|
return $langs->trans("NotAvailable");
|
2009-01-28 16:09:37 +01:00
|
|
|
|
}
|
2005-11-11 21:11:57 +01:00
|
|
|
|
}
|
2006-02-08 07:08:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
2006-03-22 00:47:01 +01:00
|
|
|
|
/*
|
2006-05-06 23:09:26 +02:00
|
|
|
|
\brief Cr<EFBFBD>e un bon de commande sur disque en fonction d'un mod<EFBFBD>le
|
2006-03-22 00:47:01 +01:00
|
|
|
|
\param db objet base de donn<EFBFBD>e
|
|
|
|
|
|
\param id id de la propale <EFBFBD> cr<EFBFBD>er
|
2008-10-28 21:05:23 +01:00
|
|
|
|
\param modele force le modele <EFBFBD> utiliser ('' to not force)
|
2006-03-22 00:47:01 +01:00
|
|
|
|
\param outputlangs objet lang a utiliser pour traduction
|
|
|
|
|
|
*/
|
2008-10-28 21:05:23 +01:00
|
|
|
|
function commande_pdf_create($db, $id, $modele, $outputlangs)
|
2006-03-22 00:47:01 +01:00
|
|
|
|
{
|
|
|
|
|
|
global $conf,$langs;
|
|
|
|
|
|
$langs->load("orders");
|
2006-11-11 02:49:14 +01:00
|
|
|
|
|
2006-03-22 00:47:01 +01:00
|
|
|
|
$dir = DOL_DOCUMENT_ROOT."/includes/modules/commande/";
|
2006-05-06 01:57:38 +02:00
|
|
|
|
$modelisok=0;
|
|
|
|
|
|
$liste=array();
|
|
|
|
|
|
|
2006-05-05 16:54:37 +02:00
|
|
|
|
// Positionne modele sur le nom du modele de commande <20> utiliser
|
2006-05-06 01:57:38 +02:00
|
|
|
|
$file = "pdf_".$modele.".modules.php";
|
|
|
|
|
|
if ($modele && file_exists($dir.$file)) $modelisok=1;
|
|
|
|
|
|
|
2006-11-11 02:49:14 +01:00
|
|
|
|
// Si model pas encore bon
|
2006-05-06 01:57:38 +02:00
|
|
|
|
if (! $modelisok)
|
2006-03-22 00:47:01 +01:00
|
|
|
|
{
|
2006-05-06 01:57:38 +02:00
|
|
|
|
if ($conf->global->COMMANDE_ADDON_PDF) $modele = $conf->global->COMMANDE_ADDON_PDF;
|
|
|
|
|
|
$file = "pdf_".$modele.".modules.php";
|
|
|
|
|
|
if (file_exists($dir.$file)) $modelisok=1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2006-11-11 02:49:14 +01:00
|
|
|
|
// Si model pas encore bon
|
2006-05-06 01:57:38 +02:00
|
|
|
|
if (! $modelisok)
|
|
|
|
|
|
{
|
|
|
|
|
|
$model=new ModelePDFCommandes();
|
|
|
|
|
|
$liste=$model->liste_modeles($db);
|
|
|
|
|
|
$modele=key($liste); // Renvoie premiere valeur de cl<63> trouv<75> dans le tableau
|
|
|
|
|
|
$file = "pdf_".$modele.".modules.php";
|
|
|
|
|
|
if (file_exists($dir.$file)) $modelisok=1;
|
2006-03-22 00:47:01 +01:00
|
|
|
|
}
|
2006-11-11 02:49:14 +01:00
|
|
|
|
|
2006-03-22 00:47:01 +01:00
|
|
|
|
// Charge le modele
|
2006-05-06 01:57:38 +02:00
|
|
|
|
if ($modelisok)
|
2006-03-22 00:47:01 +01:00
|
|
|
|
{
|
|
|
|
|
|
$classname = "pdf_".$modele;
|
|
|
|
|
|
require_once($dir.$file);
|
2006-11-11 02:49:14 +01:00
|
|
|
|
|
2006-03-22 00:47:01 +01:00
|
|
|
|
$obj = new $classname($db);
|
2006-11-11 02:49:14 +01:00
|
|
|
|
|
2008-10-28 21:05:23 +01:00
|
|
|
|
// We save charset_output to restore it because write_file can change it if needed for
|
|
|
|
|
|
// output format that does not support UTF8.
|
|
|
|
|
|
$sav_charset_output=$outputlangs->charset_output;
|
2007-10-22 01:56:56 +02:00
|
|
|
|
if ($obj->write_file($id, $outputlangs) > 0)
|
2006-03-22 00:47:01 +01:00
|
|
|
|
{
|
2008-10-28 21:05:23 +01:00
|
|
|
|
$outputlangs->charset_output=$sav_charset_output;
|
2006-03-22 00:47:01 +01:00
|
|
|
|
// on supprime l'image correspondant au preview
|
|
|
|
|
|
commande_delete_preview($db, $id);
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2008-10-28 21:05:23 +01:00
|
|
|
|
$outputlangs->charset_output=$sav_charset_output;
|
2009-02-20 23:53:15 +01:00
|
|
|
|
dol_syslog("Erreur dans commande_pdf_create");
|
|
|
|
|
|
dol_print_error($db,$obj->pdferror());
|
2006-03-22 00:47:01 +01:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2006-05-06 01:57:38 +02:00
|
|
|
|
if (! $conf->global->COMMANDE_ADDON_PDF)
|
|
|
|
|
|
{
|
|
|
|
|
|
print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_ADDON_PDF_NotDefined");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$dir.$file);
|
|
|
|
|
|
}
|
2006-03-22 00:47:01 +01:00
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2006-02-08 07:08:15 +01:00
|
|
|
|
}
|
2006-03-22 00:47:01 +01:00
|
|
|
|
|
2006-06-09 16:58:53 +02:00
|
|
|
|
/**
|
|
|
|
|
|
\brief Supprime l'image de pr<EFBFBD>visualitation, pour le cas de r<EFBFBD>g<EFBFBD>n<EFBFBD>ration de commande
|
|
|
|
|
|
\param db objet base de donn<EFBFBD>e
|
|
|
|
|
|
\param commandeid id de la commande <EFBFBD> effacer
|
|
|
|
|
|
\param commanderef r<EFBFBD>f<EFBFBD>rence de la commande si besoin
|
|
|
|
|
|
*/
|
2006-06-09 16:38:19 +02:00
|
|
|
|
function commande_delete_preview($db, $commandeid, $commanderef='')
|
2006-02-08 07:08:15 +01:00
|
|
|
|
{
|
2006-02-09 09:37:11 +01:00
|
|
|
|
global $langs,$conf;
|
2006-02-08 07:08:15 +01:00
|
|
|
|
|
2006-06-09 16:38:19 +02:00
|
|
|
|
if (!$commanderef)
|
|
|
|
|
|
{
|
|
|
|
|
|
$com = new Commande($db,"",$commandeid);
|
|
|
|
|
|
$com->fetch($commandeid);
|
|
|
|
|
|
$commanderef = $com->ref;
|
|
|
|
|
|
}
|
2006-11-11 02:49:14 +01:00
|
|
|
|
|
2006-02-09 09:37:11 +01:00
|
|
|
|
if ($conf->commande->dir_output)
|
2006-06-09 14:40:33 +02:00
|
|
|
|
{
|
2009-04-29 20:02:50 +02:00
|
|
|
|
$comref = dol_sanitizeFileName($commanderef);
|
2006-06-09 14:40:33 +02:00
|
|
|
|
$dir = $conf->commande->dir_output . "/" . $comref ;
|
|
|
|
|
|
$file = $dir . "/" . $comref . ".pdf.png";
|
|
|
|
|
|
$multiple = $file . ".";
|
2006-11-11 02:49:14 +01:00
|
|
|
|
|
2006-06-09 16:38:19 +02:00
|
|
|
|
if ( file_exists( $file ) && is_writable( $file ) )
|
|
|
|
|
|
{
|
|
|
|
|
|
if ( ! unlink($file) )
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error=$langs->trans("ErrorFailedToOpenFile",$file);
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2006-06-09 14:40:33 +02:00
|
|
|
|
{
|
2006-06-09 16:38:19 +02:00
|
|
|
|
for ($i = 0; $i < 20; $i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
$preview = $multiple.$i;
|
2006-11-11 02:49:14 +01:00
|
|
|
|
|
2006-06-09 14:40:33 +02:00
|
|
|
|
if ( file_exists( $preview ) && is_writable( $preview ) )
|
|
|
|
|
|
{
|
|
|
|
|
|
if ( ! unlink($preview) )
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->error=$langs->trans("ErrorFailedToOpenFile",$preview);
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2006-06-09 16:38:19 +02:00
|
|
|
|
}
|
2006-02-08 07:08:15 +01:00
|
|
|
|
}
|
2004-12-28 18:14:25 +01:00
|
|
|
|
?>
|