dolibarr/htdocs/core/modules/facture/modules_facture.php

261 lines
6.8 KiB
PHP
Raw Normal View History

<?php
2005-03-08 10:38:12 +00:00
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
2012-12-30 14:13:49 +00:00
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
*
* 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 3 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
2011-07-31 23:24:38 +00:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
* \file htdocs/core/modules/facture/modules_facture.php
* \ingroup facture
* \brief Fichier contenant la classe mere de generation des factures en PDF
* et la classe mere de numerotation des factures
2008-10-21 21:27:20 +00:00
*/
require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Requis car utilise dans les classes qui heritent
/**
* Parent class of invoice document generators
2008-10-21 21:27:20 +00:00
*/
abstract class ModelePDFFactures extends CommonDocGenerator
{
var $error='';
2005-12-07 14:06:20 +00:00
/**
2011-05-06 13:35:18 +00:00
* Return list of active generation modules
2012-03-13 08:38:00 +00:00
*
* @param DoliDB $db Database handler
* @param string $maxfilenamelength Max length of value to show
* @return array List of templates
*/
2012-03-23 17:19:50 +00:00
static function liste_modeles($db,$maxfilenamelength=0)
{
2009-05-26 12:54:32 +00:00
global $conf;
2008-10-21 21:27:20 +00:00
$type='invoice';
$liste=array();
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
2012-03-13 08:38:00 +00:00
$liste=getListOfModels($db,$type,$maxfilenamelength);
return $liste;
}
2004-07-27 15:15:37 +00:00
}
/**
* Classe mere des modeles de numerotation des references de facture
2008-10-21 21:27:20 +00:00
*/
2011-09-29 08:08:26 +00:00
abstract class ModeleNumRefFactures
{
var $error='';
2008-10-21 21:27:20 +00:00
2012-03-16 23:22:48 +00:00
/**
* Return if a module can be used or not
*
* @return boolean true if module can be used
2008-10-21 21:27:20 +00:00
*/
function isEnabled()
{
return true;
}
2012-03-16 23:22:48 +00:00
/**
* Renvoi la description par defaut du modele de numerotation
*
* @return string Texte descripif
2008-10-21 21:27:20 +00:00
*/
function info()
{
global $langs;
$langs->load("bills");
return $langs->trans("NoDescription");
}
2008-10-21 21:27:20 +00:00
2012-03-16 23:22:48 +00:00
/**
* Renvoi un exemple de numerotation
*
* @return string Example
2008-10-21 21:27:20 +00:00
*/
function getExample()
{
global $langs;
$langs->load("bills");
return $langs->trans("NoExample");
}
2008-10-21 21:27:20 +00:00
2012-03-16 23:22:48 +00:00
/**
* Test si les numeros deja en vigueur dans la base ne provoquent pas
* de conflits qui empecheraient cette numerotation de fonctionner.
*
* @return boolean false si conflit, true si ok
2008-10-21 21:27:20 +00:00
*/
function canBeActivated()
{
return true;
}
2008-10-21 21:27:20 +00:00
2012-03-16 23:22:48 +00:00
/**
* Renvoi prochaine valeur attribuee
*
2012-03-19 16:18:11 +00:00
* @param Societe $objsoc Objet societe
* @param Facture $facture Objet facture
* @return string Value
2008-10-21 21:27:20 +00:00
*/
function getNextValue($objsoc,$facture)
{
global $langs;
return $langs->trans("NotAvailable");
}
2008-10-21 21:27:20 +00:00
2012-03-16 23:22:48 +00:00
/**
* Renvoi version du modele de numerotation
*
* @return string Valeur
2008-10-21 21:27:20 +00:00
*/
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");
2008-10-21 21:27:20 +00:00
}
}
2004-12-28 15:32:24 +00:00
/**
* Create a document onto disk according to template module.
2011-09-12 17:08:02 +00:00
*
2012-03-26 20:39:43 +00:00
* @param DoliDB $db Database handler
* @param Object $object Object invoice
* @param string $modele Force template to use ('' to not force)
* @param Translate $outputlangs objet lang a utiliser pour traduction
* @param int $hidedetails Hide details of lines
* @param int $hidedesc Hide description
* @param int $hideref Hide ref
* @return int <0 if KO, >0 if OK
2008-10-21 21:27:20 +00:00
*/
2013-01-26 09:35:30 +00:00
function facture_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
{
2011-07-04 10:35:48 +00:00
global $conf,$user,$langs;
2011-08-10 23:20:55 +00:00
$langs->load("bills");
2011-12-05 18:03:36 +00:00
$error=0;
2010-12-22 20:17:14 +00:00
// Increase limit for PDF build
$err=error_reporting();
error_reporting(0);
@set_time_limit(120);
error_reporting($err);
2011-02-20 19:04:14 +00:00
$srctemplatepath='';
2011-05-06 13:35:18 +00:00
// Positionne le modele sur le nom du modele a utiliser
if (! dol_strlen($modele))
{
2010-10-19 08:01:25 +00:00
if (! empty($conf->global->FACTURE_ADDON_PDF))
{
$modele = $conf->global->FACTURE_ADDON_PDF;
}
else
{
2010-04-18 21:20:34 +00:00
$modele = 'crabe';
}
}
2011-02-20 19:04:14 +00:00
// If selected modele is a filename template (then $modele="modelname:filename")
$tmp=explode(':',$modele,2);
if (! empty($tmp[1]))
{
$modele=$tmp[0];
$srctemplatepath=$tmp[1];
}
// Search template files
$file=''; $classname=''; $filefound=0;
2012-03-01 08:24:45 +00:00
$dirmodels=array('/');
if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']);
foreach($dirmodels as $reldir)
{
foreach(array('doc','pdf') as $prefix)
{
$file = $prefix."_".$modele.".modules.php";
// On verifie l'emplacement du modele
$file=dol_buildpath($reldir."core/modules/facture/doc/".$file,0);
if (file_exists($file))
{
$filefound=1;
$classname=$prefix.'_'.$modele;
break;
}
}
if ($filefound) break;
}
2011-02-20 19:04:14 +00:00
// Charge le modele
2011-02-20 19:04:14 +00:00
if ($filefound)
{
require_once $file;
$obj = new $classname($db);
2008-10-28 20:05:23 +00: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;
2013-01-26 09:35:30 +00:00
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
{
2008-10-28 20:05:23 +00:00
$outputlangs->charset_output=$sav_charset_output;
2011-08-10 23:20:55 +00:00
// We delete old preview
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
dol_delete_preview($object);
// Success in building document. We build meta file.
dol_meta_create($object);
2011-07-04 10:35:48 +00:00
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
2011-07-04 10:35:48 +00:00
$interface=new Interfaces($db);
$result=$interface->run_triggers('BILL_BUILDDOC',$object,$user,$langs,$conf);
2013-07-19 15:18:44 +00:00
if ($result < 0) { $error++; $errors=$interface->errors; }
2011-07-04 10:35:48 +00:00
// Fin appel triggers
2011-08-10 23:20:55 +00:00
return 1;
}
else
{
2008-10-28 20:05:23 +00:00
$outputlangs->charset_output=$sav_charset_output;
dol_print_error($db,"facture_pdf_create Error: ".$obj->error);
2006-04-23 14:01:42 +00:00
return -1;
}
2005-12-07 14:06:20 +00:00
}
else
2005-12-07 14:06:20 +00:00
{
2012-01-06 09:19:07 +00:00
dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file));
2006-04-23 14:01:42 +00:00
return -1;
2005-12-07 14:06:20 +00:00
}
}
2009-05-26 12:54:32 +00:00
?>