2
0
forked from Wavyzz/dolibarr

Merge branch 'oop-pdf' of github.com:marcosgdf/dolibarr into

marcosgdf-oop-pdf

Conflicts:
	htdocs/projet/class/project.class.php
This commit is contained in:
Laurent Destailleur
2014-09-23 00:02:19 +02:00
38 changed files with 586 additions and 993 deletions

View File

@@ -3505,4 +3505,96 @@ abstract class CommonObject
return $result;
}
/**
* Common function for all objects extending CommonObject for generating documents
*
* @param string $modelspath Relative folder where models are placed
* @param string $modele Model to use
* @param Translate $outputlangs Language to use
* @param int $hidedetails 1 to hide details. 0 by default
* @param int $hidedesc 1 to hide product description. 0 by default
* @param int $hideref 1 to hide product reference. 0 by default
* @return int 1 if OK -1 if not OK
*/
protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref)
{
global $conf, $langs;
$srctemplatepath='';
// Increase limit for PDF build
$err=error_reporting();
error_reporting(0);
@set_time_limit(120);
error_reporting($err);
// 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;
$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.$modelspath.$file,0);
if (file_exists($file))
{
$filefound=1;
$classname=$prefix.'_'.$modele;
break;
}
}
if ($filefound) break;
}
// Charge le modele
if ($filefound)
{
require_once $file;
$obj = new $classname($this->db);
//$obj->message = $message;
// 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;
if ($obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
{
$outputlangs->charset_output=$sav_charset_output;
// We delete old preview
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
dol_delete_preview($this);
// Success in building document. We build meta file.
dol_meta_create($this);
return 1;
}
else
{
$outputlangs->charset_output=$sav_charset_output;
dol_print_error($this->db,"Error generating document for ".__CLASS__.". Error: ".$obj->error);
return -1;
}
}
else
{
dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file));
return -1;
}
}
}

View File

@@ -174,7 +174,7 @@ function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filte
if ($regenerate || ! dol_is_file($filename))
{
if ($usestdout) print "Build PDF for invoice ".$obj->facnumber." - Lang = ".$outputlangs->defaultlang."\n";
$result=facture_pdf_create($db, $fac, $regenerate?$regenerate:$fac->modelpdf, $outputlangs);
$result= $fac->generateDocument($regenerate?$regenerate:$fac->modelpdf, $outputlangs);
}
else {
if ($usestdout) print "PDF for invoice ".$obj->facnumber." already exists\n";

View File

@@ -5,6 +5,7 @@
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.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
@@ -159,94 +160,9 @@ abstract class ModeleNumRefCommandes
* @param int $hidedesc Hide description
* @param int $hideref Hide ref
* @return int 0 if KO, 1 if OK
* @deprecated Use the new function generateDocument of Commande class
*/
function commande_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
function commande_pdf_create(DoliDB $db, Commande $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
{
global $conf,$user,$langs,$hookmanager;
$langs->load("orders");
$error=0;
$srctemplatepath='';
// Positionne le modele sur le nom du modele a utiliser
if (! dol_strlen($modele))
{
if (! empty($conf->global->COMMANDE_ADDON_PDF))
{
$modele = $conf->global->COMMANDE_ADDON_PDF;
}
else
{
$modele = 'einstein';
}
}
// 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;
$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/commande/doc/".$file,0);
if (file_exists($file))
{
$filefound=1;
$classname=$prefix.'_'.$modele;
break;
}
}
if ($filefound) break;
}
// Charge le modele
if ($filefound)
{
require_once $file;
$obj = new $classname($db);
//$obj->message = $message;
// 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;
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
{
$outputlangs->charset_output=$sav_charset_output;
// 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);
return 1;
}
else
{
$outputlangs->charset_output=$sav_charset_output;
dol_print_error($db,"order_pdf_create Error: ".$obj->error);
return -1;
}
}
else
{
dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file));
return -1;
}
return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
}

View File

@@ -6,6 +6,7 @@
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.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
@@ -154,92 +155,9 @@ class ModelNumRefContracts
* @param int $hidedesc Hide description
* @param int $hideref Hide ref
* @return int 0 if KO, 1 if OK
* @deprecated Use the new function generateDocument of Contrat class
*/
function contract_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
function contract_pdf_create(DoliDB $db, Contrat $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
{
global $conf,$langs,$user,$hookmanager;
$langs->load("contracts");
$error=0;
$srctemplatepath='';
// Positionne modele sur le nom du modele de contrat a utiliser
if (! dol_strlen($modele))
{
if (! empty($conf->global->CONTRACT_ADDON_PDF))
{
$modele = $conf->global->CONTRACT_ADDON_PDF;
}
else
{
$modele = 'strato';
}
}
// 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;
$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/contract/doc/".$file,0);
if (file_exists($file))
{
$filefound=1;
$classname=$prefix.'_'.$modele;
break;
}
}
if ($filefound) break;
}
// Charge le modele
if ($filefound)
{
require_once $file;
$obj = new $classname($db);
// 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;
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
{
$outputlangs->charset_output=$sav_charset_output;
// 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);
return 1;
}
else
{
$outputlangs->charset_output=$sav_charset_output;
dol_print_error($db,"contract_pdf_create Error: ".$obj->error);
return 0;
}
}
else
{
print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
return 0;
}
return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
}

View File

@@ -6,6 +6,7 @@
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2011-2013 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.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
@@ -149,100 +150,9 @@ abstract class ModelNumRefExpedition
* @param string $modele Force le modele a utiliser ('' to not force)
* @param Translate $outputlangs Objet lang a utiliser pour traduction
* @return int <=0 if KO, >0 if OK
* @deprecated Use the new function generateDocument of Expedition class
*/
function expedition_pdf_create($db, $object, $modele, $outputlangs)
function expedition_pdf_create(DoliDB $db, Expedition $object, $modele, $outputlangs)
{
global $conf,$user,$langs;
$langs->load("sendings");
$error=0;
$srctemplatepath='';
// Sets the model on the model name to use
if (! dol_strlen($modele))
{
if (! empty($conf->global->EXPEDITION_ADDON_PDF))
{
$modele = $conf->global->EXPEDITION_ADDON_PDF;
}
else
{
$modele = 'rouget';
}
}
// If selected model 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;
$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";
// We check the model location
$file=dol_buildpath($reldir."core/modules/expedition/doc/".$file,0);
if (file_exists($file))
{
$filefound=1;
$classname=$prefix.'_'.$modele;
break;
}
}
if ($filefound) break;
}
// Load the model
if ($filefound)
{
require_once $file;
$obj = new $classname($db);
$result=$object->fetch_origin();
// 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;
if ($obj->write_file($object, $outputlangs, $srctemplatepath) > 0)
{
$outputlangs->charset_output=$sav_charset_output;
// we delete preview files
//require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
//dol_delete_preview($object);
return 1;
}
else
{
$outputlangs->charset_output=$sav_charset_output;
dol_syslog("Erreur dans expedition_pdf_create");
dol_print_error($db,$obj->error);
return 0;
}
}
else
{
if (! $conf->global->EXPEDITION_ADDON_PDF)
{
print $langs->trans("Error")." ".$langs->trans("Error_EXPEDITION_ADDON_PDF_NotDefined");
}
else
{
print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
}
return 0;
}
return $object->generateDocument($modele, $outputlangs);
}

View File

@@ -3,6 +3,7 @@
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.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
@@ -154,101 +155,10 @@ abstract class ModeleNumRefFactures
* @param int $hidedesc Hide description
* @param int $hideref Hide ref
* @return int <0 if KO, >0 if OK
* @deprecated Use the new function generateDocument of Facture class
*/
function facture_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
function facture_pdf_create(DoliDB $db, Facture $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
{
global $conf,$user,$langs;
$langs->load("bills");
$error=0;
// Increase limit for PDF build
$err=error_reporting();
error_reporting(0);
@set_time_limit(120);
error_reporting($err);
$srctemplatepath='';
// Positionne le modele sur le nom du modele a utiliser
if (! dol_strlen($modele))
{
if (! empty($conf->global->FACTURE_ADDON_PDF))
{
$modele = $conf->global->FACTURE_ADDON_PDF;
}
else
{
$modele = 'crabe';
}
}
// 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;
$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;
}
// Charge le modele
if ($filefound)
{
require_once $file;
$obj = new $classname($db);
// 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;
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
{
$outputlangs->charset_output=$sav_charset_output;
// 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);
return 1;
}
else
{
$outputlangs->charset_output=$sav_charset_output;
dol_print_error($db,"facture_pdf_create Error: ".$obj->error);
return -1;
}
}
else
{
dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file));
return -1;
}
return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
}

View File

@@ -4,6 +4,7 @@
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2006-2011 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2011-2012 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.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
@@ -154,92 +155,10 @@ abstract class ModeleNumRefDeliveryOrder
* @param string $modele force le modele a utiliser ('' to not force)
* @param Translate $outputlangs objet lang a utiliser pour traduction
* @return int 0 if KO, 1 if OK
* @deprecated Use the new function generateDocument of Livraison class
*/
function delivery_order_pdf_create($db, $object, $modele, $outputlangs='')
function delivery_order_pdf_create(DoliDB $db, Livraison $object, $modele, $outputlangs='')
{
global $conf,$user,$langs;
$langs->load("deliveries");
$error=0;
$srctemplatepath='';
// Positionne modele sur le nom du modele de bon de livraison a utiliser
if (! dol_strlen($modele))
{
if (! empty($conf->global->LIVRAISON_ADDON_PDF))
{
$modele = $conf->global->LIVRAISON_ADDON_PDF;
}
else
{
$modele = 'typhon';
}
}
// 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;
$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/livraison/pdf/".$file,0);
if (file_exists($file))
{
$filefound=1;
$classname=$prefix.'_'.$modele;
break;
}
}
if ($filefound) break;
}
// Charge le modele
if ($filefound)
{
require_once $file;
$obj = new $classname($db);
// 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;
if ($obj->write_file($object,$outputlangs) > 0)
{
$outputlangs->charset_output=$sav_charset_output;
// we delete preview files
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
dol_delete_preview($object);
return 1;
}
else
{
$outputlangs->charset_output=$sav_charset_output;
dol_syslog("Erreur dans delivery_order_pdf_create");
dol_print_error($db,$obj->error);
return 0;
}
}
else
{
print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
return 0;
}
return $object->generateDocument($modele, $outputlangs);
}

View File

@@ -1,5 +1,6 @@
<?php
/* Copyright (C) 2010-2014 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.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
@@ -151,93 +152,10 @@ abstract class ModeleNumRefProjects
* @param int $hidedesc Hide description
* @param int $hideref Hide ref
* @return int 0 if KO, 1 if OK
* @deprecated Use the new function generateDocument of Project class
*/
function project_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
function project_pdf_create(DoliDB $db, Project $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
{
global $conf,$langs;
$langs->load("projects");
$error=0;
$srctemplatepath='';
// Positionne modele sur le nom du modele de projet a utiliser
if (! dol_strlen($modele))
{
if (! empty($conf->global->PROJECT_ADDON_PDF))
{
$modele = $conf->global->PROJECT_ADDON_PDF;
}
else
{
$modele='baleine';
}
}
// 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;
$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/project/pdf/".$file,0);
if (file_exists($file))
{
$filefound=1;
$classname=$prefix.'_'.$modele;
break;
}
}
if ($filefound) break;
}
// Charge le modele
if ($filefound)
{
require_once $file;
$obj = new $classname($db);
// 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;
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
{
$outputlangs->charset_output=$sav_charset_output;
// we delete preview files
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);
return 1;
}
else
{
$outputlangs->charset_output=$sav_charset_output;
dol_print_error($db,"project_pdf_create Error: ".$obj->error);
return 0;
}
}
else
{
print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
return 0;
}
return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
}

View File

@@ -1,6 +1,7 @@
<?php
/* Copyright (C) 2010 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010 Florian Henry <florian.henry<àopen-concept.pro>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.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
@@ -152,92 +153,10 @@ abstract class ModeleNumRefTask
* @param int $hideref Hide ref
* @param HookManager $hookmanager Hook manager instance
* @return int 0 if KO, 1 if OK
* @deprecated Use the new function generateDocument of Task class
*/
function task_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false)
function task_pdf_create(DoliDB $db, Task $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $hookmanager=false)
{
global $conf,$langs;
$langs->load("projects");
$error=0;
$srctemplatepath='';
// Positionne modele sur le nom du modele de projet a utiliser
if (! dol_strlen($modele))
{
if (! empty($conf->global->PROJECT_TASK_ADDON_PDF))
{
$modele = $conf->global->PROJECT_TASK_ADDON_PDF;
}
else
{
$modele='nodefault';
}
}
// 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;
$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/project/task/pdf/".$file,0);
if (file_exists($file))
{
$filefound=1;
$classname=$prefix.'_'.$modele;
break;
}
}
if ($filefound) break;
}
// Charge le modele
if ($filefound)
{
require_once $file;
$obj = new $classname($db);
// 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;
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $hookmanager) > 0)
{
$outputlangs->charset_output=$sav_charset_output;
// we delete preview files
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);
return 1;
}
else
{
$outputlangs->charset_output=$sav_charset_output;
dol_print_error($db,"task_pdf_create Error: ".$obj->error);
return 0;
}
}
else
{
print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
return 0;
}
return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
}

View File

@@ -3,6 +3,7 @@
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.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
@@ -155,95 +156,10 @@ abstract class ModeleNumRefPropales
* @param int $hidedesc Hide description
* @param int $hideref Hide ref
* @return int 0 if KO, 1 if OK
* @deprecated Use the new function generateDocument of Propal class
*/
function propale_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
function propale_pdf_create(DoliDB $db, Propal $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
{
global $conf,$user,$langs;
$langs->load("propale");
$error=0;
$srctemplatepath='';
// Positionne le modele sur le nom du modele a utiliser
if (! dol_strlen($modele))
{
if (! empty($conf->global->PROPALE_ADDON_PDF))
{
$modele = $conf->global->PROPALE_ADDON_PDF;
}
else
{
$modele = 'azur';
}
}
// 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;
$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/propale/doc/".$file,0);
if (file_exists($file))
{
$filefound=1;
$classname=$prefix.'_'.$modele;
break;
}
}
if ($filefound) break;
}
// Charge le modele
if ($filefound)
{
require_once $file;
$obj = new $classname($db);
//$obj->message = $message;
// 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;
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
{
$outputlangs->charset_output=$sav_charset_output;
// 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);
return 1;
}
else
{
$outputlangs->charset_output=$sav_charset_output;
dol_print_error($db,"propal_pdf_create Error: ".$obj->error);
return -1;
}
}
else
{
dol_print_error('',$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file));
return -1;
}
return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
}

View File

@@ -2,6 +2,7 @@
/* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.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
@@ -143,105 +144,10 @@ abstract class ModeleNumRefSuppliersInvoices
* @param int $hidedesc Hide description
* @param int $hideref Hide ref
* @return int 0 if KO, 1 if OK
*
*/
function supplier_invoice_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
{
global $conf, $user, $langs;
$langs->load("suppliers");
$error=0;
// Increase limit for PDF build
$err=error_reporting();
error_reporting(0);
@set_time_limit(120);
error_reporting($err);
$srctemplatepath='';
// Set the model on the model name to use
if (! dol_strlen($modele))
{
if (! empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF))
{
$modele = $conf->global->INVOICE_SUPPLIER_ADDON_PDF;
}
else
{
$modele = 'canelle';
}
}
// 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;
$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";
// We checked the location of the model
$file=dol_buildpath($reldir."core/modules/supplier_invoice/pdf/".$file,0);
if (file_exists($file))
{
$filefound=1;
$classname=$prefix.'_'.$modele;
break;
}
}
if ($filefound) break;
}
// Load the model
if ($filefound)
{
require_once $file;
$obj = new $classname($db,$object);
// 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;
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
{
$outputlangs->charset_output=$sav_charset_output;
// we delete preview files
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
dol_delete_preview($object);
return 1;
}
else
{
$outputlangs->charset_output=$sav_charset_output;
dol_syslog("Erreur dans supplier_invoice_pdf_create");
dol_print_error($db,$obj->error);
return 0;
}
}
else
{
if (! $conf->global->INVOICE_SUPPLIER_ADDON_PDF)
{
print $langs->trans("Error")." ".$langs->trans("Error_INVOICE_SUPPLIER_ADDON_PDF_NotDefined");
}
else
{
print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
}
return 0;
}
return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
}

View File

@@ -58,9 +58,8 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
* Constructor
*
* @param DoliDB $db Database handler
* @param Object $object Supplier invoice
*/
function __construct($db,$object)
function __construct($db)
{
global $conf,$langs,$mysoc;
@@ -91,12 +90,6 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
$this->franchise=!$mysoc->tva_assuj;
// Get source company
if (! is_object($object->thirdparty)) $object->fetch_thirdparty();
if (! is_object($object->thirdparty)) $object->thirdparty=$mysoc; // If fetch_thirdparty fails, object has no socid (specimen)
$this->emetteur=$object->thirdparty;
if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined
// Defini position des colonnes
$this->posxdesc=$this->marge_gauche+1;
$this->posxtva=112;
@@ -139,6 +132,12 @@ class pdf_canelle extends ModelePDFSuppliersInvoices
{
global $user,$langs,$conf,$mysoc,$hookmanager;
// Get source company
if (! is_object($object->thirdparty)) $object->fetch_thirdparty();
if (! is_object($object->thirdparty)) $object->thirdparty=$mysoc; // If fetch_thirdparty fails, object has no socid (specimen)
$this->emetteur=$object->thirdparty;
if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default, if was not defined
if (! is_object($outputlangs)) $outputlangs=$langs;
// For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO
if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1';

View File

@@ -5,6 +5,7 @@
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2011-2013 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2014 Marcos García <marcosgdf@gmail.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
@@ -149,104 +150,10 @@ abstract class ModeleNumRefSuppliersOrders
* @param int $hidedesc Hide description
* @param int $hideref Hide ref
* @return int 0 if KO, 1 if OK
* @deprecated Use the new function generateDocument of CommandeFournisseur class
*/
function supplier_order_pdf_create($db, $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
function supplier_order_pdf_create(DoliDB $db, CommandeFournisseur $object, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
{
global $conf, $user, $langs;
$langs->load("suppliers");
$error=0;
// Increase limit for PDF build
$err=error_reporting();
error_reporting(0);
@set_time_limit(120);
error_reporting($err);
$srctemplatepath='';
// Sets the model on the model name to use
if (! dol_strlen($modele))
{
if (! empty($conf->global->COMMANDE_SUPPLIER_ADDON_PDF))
{
$modele = $conf->global->COMMANDE_SUPPLIER_ADDON_PDF;
}
else
{
$modele = 'muscadet';
}
}
// If selected model 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;
$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";
// We check the model location
$file=dol_buildpath($reldir."core/modules/supplier_order/pdf/".$file,0);
if (file_exists($file))
{
$filefound=1;
$classname=$prefix.'_'.$modele;
break;
}
}
if ($filefound) break;
}
// Load the model
if ($filefound)
{
require_once $file;
$obj = new $classname($db,$object);
// 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;
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref) > 0)
{
$outputlangs->charset_output=$sav_charset_output;
// we delete preview files
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
dol_delete_preview($object);
return 1;
}
else
{
$outputlangs->charset_output=$sav_charset_output;
dol_syslog("Erreur dans supplier_order_pdf_create");
dol_print_error($db,$obj->error);
return 0;
}
}
else
{
if (! $conf->global->COMMANDE_SUPPLIER_ADDON_PDF)
{
print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_SUPPLIER_ADDON_PDF_NotDefined");
}
else
{
print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
}
return 0;
}
return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
}

View File

@@ -61,9 +61,8 @@ class pdf_muscadet extends ModelePDFSuppliersOrders
* Constructor
*
* @param DoliDB $db Database handler
* @param Object $object Supplier order
*/
function __construct($db,$object)
function __construct($db)
{
global $conf,$langs,$mysoc;