uniformize code with commande
This commit is contained in:
parent
c3f1b8cc4b
commit
0eea44a1ed
@ -4,6 +4,7 @@
|
|||||||
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
||||||
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
|
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
|
||||||
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
||||||
|
* Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -30,6 +31,7 @@
|
|||||||
*/
|
*/
|
||||||
require_once(DOL_DOCUMENT_ROOT.'/lib/pdf.lib.php');
|
require_once(DOL_DOCUMENT_ROOT.'/lib/pdf.lib.php');
|
||||||
require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php');
|
require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php');
|
||||||
|
require_once(DOL_DOCUMENT_ROOT."/compta/bank/class/account.class.php"); // requis car utilise par les classes qui heritent
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,8 +44,8 @@ class ModelePDFSuppliersOrders
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Return list of active generation modules
|
* Return list of active generation modules
|
||||||
* \param $db Database handler
|
* @param $db Database handler
|
||||||
*/
|
*/
|
||||||
function liste_modeles($db)
|
function liste_modeles($db)
|
||||||
{
|
{
|
||||||
@ -70,16 +72,16 @@ class ModeleNumRefSuppliersOrders
|
|||||||
{
|
{
|
||||||
var $error='';
|
var $error='';
|
||||||
|
|
||||||
/** \brief Return if a module can be used or not
|
/** Return if a module can be used or not
|
||||||
* \return boolean true if module can be used
|
* @return boolean true if module can be used
|
||||||
*/
|
*/
|
||||||
function isEnabled()
|
function isEnabled()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Renvoi la description par defaut du modele de numerotation
|
/** Renvoie la description par defaut du modele de numerotation
|
||||||
* \return string Texte descripif
|
* @return string Texte descripif
|
||||||
*/
|
*/
|
||||||
function info()
|
function info()
|
||||||
{
|
{
|
||||||
@ -88,8 +90,8 @@ class ModeleNumRefSuppliersOrders
|
|||||||
return $langs->trans("NoDescription");
|
return $langs->trans("NoDescription");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Renvoi un exemple de num<EFBFBD>rotation
|
/** Renvoie un exemple de numerotation
|
||||||
* \return string Example
|
* @return string Example
|
||||||
*/
|
*/
|
||||||
function getExample()
|
function getExample()
|
||||||
{
|
{
|
||||||
@ -98,17 +100,16 @@ class ModeleNumRefSuppliersOrders
|
|||||||
return $langs->trans("NoExample");
|
return $langs->trans("NoExample");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Test si les numeros deja en vigueur dans la base ne provoquent pas de
|
/** Test si les numeros deja en vigueur dans la base ne provoquent pas de conflits qui empecheraient cette numerotation de fonctionner.
|
||||||
* de conflits qui empechera cette numerotation de fonctionner.
|
* @return boolean false si conflit, true si ok
|
||||||
* \return boolean false si conflit, true si ok
|
|
||||||
*/
|
*/
|
||||||
function canBeActivated()
|
function canBeActivated()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Renvoi prochaine valeur attribuee
|
/** Renvoie prochaine valeur attribuee
|
||||||
* \return string Valeur
|
* @return string Valeur
|
||||||
*/
|
*/
|
||||||
function getNextValue()
|
function getNextValue()
|
||||||
{
|
{
|
||||||
@ -116,8 +117,8 @@ class ModeleNumRefSuppliersOrders
|
|||||||
return $langs->trans("NotAvailable");
|
return $langs->trans("NotAvailable");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Renvoi version du module numerotation
|
/** Renvoie version du module numerotation
|
||||||
* \return string Valeur
|
* @return string Valeur
|
||||||
*/
|
*/
|
||||||
function getVersion()
|
function getVersion()
|
||||||
{
|
{
|
||||||
@ -133,51 +134,70 @@ class ModeleNumRefSuppliersOrders
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create object on disk
|
* Cree un bon de commande sur disque en fonction d'un modele
|
||||||
* @param db objet base de donnee
|
* @param db data base object
|
||||||
* @param object object supplier order
|
* @param object object order
|
||||||
* @param model force le modele a utiliser ('' to not force)
|
* @param modele force le modele a utiliser ('' to not force)
|
||||||
* @param outputlangs objet lang a utiliser pour traduction
|
* @param outputlangs objet lang a utiliser pour traduction
|
||||||
* @return int 0 si KO, 1 si OK
|
* @param hidedetails Hide details of lines
|
||||||
|
* @param hidedesc Hide description
|
||||||
|
* @param hideref Hide ref
|
||||||
|
* @return int 0 if KO, 1 if OK
|
||||||
*/
|
*/
|
||||||
function supplier_order_pdf_create($db, $object, $model, $outputlangs)
|
function supplier_order_pdf_create($db, $object, $model, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0)
|
||||||
{
|
{
|
||||||
global $langs;
|
global $conf,$langs;
|
||||||
$langs->load("suppliers");
|
$langs->load("suppliers");
|
||||||
|
|
||||||
$dir = DOL_DOCUMENT_ROOT."/includes/modules/supplier_order/pdf/";
|
$dir = "/includes/modules/supplier_order/pdf/";
|
||||||
|
$srctemplatepath='';
|
||||||
|
$modelisok=0;
|
||||||
|
$liste=array();
|
||||||
|
|
||||||
// Positionne modele sur le nom du modele de commande fournisseur a utiliser
|
// Positionne modele sur le nom du modele de commande fournisseur a utiliser
|
||||||
if (! dol_strlen($model))
|
|
||||||
{
|
|
||||||
if (! empty($conf->global->COMMANDE_SUPPLIER_ADDON_PDF))
|
|
||||||
{
|
|
||||||
$model = $conf->global->COMMANDE_SUPPLIER_ADDON_PDF;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print $langs->trans("Error")." ".$langs->trans("Error_COMMANDE_SUPPLIER_ADDON_PDF_NotDefined");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Charge le modele
|
|
||||||
$file = "pdf_".$model.".modules.php";
|
$file = "pdf_".$model.".modules.php";
|
||||||
if (file_exists($dir.$file))
|
// On verifie l'emplacement du modele
|
||||||
|
$file = dol_buildpath($dir.$file);
|
||||||
|
if ($model && file_exists($file)) $modelisok=1;
|
||||||
|
|
||||||
|
// Si model pas encore bon
|
||||||
|
if (! $modelisok)
|
||||||
|
{
|
||||||
|
if ($conf->global->COMMANDE_SUPPLIER_ADDON_PDF) $modele = $conf->global->COMMANDE_SUPPLIER_ADDON_PDF;
|
||||||
|
$file = "pdf_".$model.".modules.php";
|
||||||
|
// On verifie l'emplacement du modele
|
||||||
|
$file = dol_buildpath($dir.$file);
|
||||||
|
if (file_exists($file)) $modelisok=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si model pas encore bon
|
||||||
|
if (! $modelisok)
|
||||||
|
{
|
||||||
|
$modele=new ModelePDFSuppliersOrders();
|
||||||
|
$liste=$modele->liste_modeles($db);
|
||||||
|
$modele=key($liste); // Renvoie la premiere valeur de cle trouvee dans le tableau
|
||||||
|
$file = "pdf_".$model.".modules.php";
|
||||||
|
// On verifie l'emplacement du modele
|
||||||
|
$file = dol_buildpath($dir.$file);
|
||||||
|
if (file_exists($file)) $modelisok=1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Charge le modele
|
||||||
|
if ($modelisok)
|
||||||
{
|
{
|
||||||
$classname = "pdf_".$model;
|
$classname = "pdf_".$model;
|
||||||
require_once($dir.$file);
|
require_once($file);
|
||||||
|
|
||||||
$obj = new $classname($db);
|
$obj = new $classname($db);
|
||||||
|
|
||||||
// We save charset_output to restore it because write_file can change it if needed for
|
// We save charset_output to restore it because write_file can change it if needed for
|
||||||
// output format that does not support UTF8.
|
// output format that does not support UTF8.
|
||||||
$sav_charset_output=$outputlangs->charset_output;
|
$sav_charset_output=$outputlangs->charset_output;
|
||||||
if ($obj->write_file($object,$outputlangs) > 0)
|
if ($obj->write_file($object, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc) > 0)
|
||||||
{
|
{
|
||||||
|
$outputlangs->charset_output=$sav_charset_output;
|
||||||
// on supprime l'image correspondant au preview
|
// on supprime l'image correspondant au preview
|
||||||
supplier_order_delete_preview($db, $object->id);
|
supplier_order_delete_preview($db, $object->id);
|
||||||
|
|
||||||
$outputlangs->charset_output=$sav_charset_output;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -189,42 +209,73 @@ function supplier_order_pdf_create($db, $object, $model, $outputlangs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
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",$dir.$file);
|
print $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$dir.$file);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete preview files
|
* Delete preview files, pour le cas de regeneration de commande
|
||||||
* @param $db
|
* @param $db data base object
|
||||||
* @param $objectid
|
* @param $comfournid id de la commande a effacer
|
||||||
|
* @param $comfournref reference de la commande si besoin
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
function supplier_order_delete_preview($db, $objectid)
|
function supplier_order_delete_preview($db, $comfournid, $comfournref='')
|
||||||
{
|
{
|
||||||
global $langs,$conf;
|
global $langs,$conf;
|
||||||
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
|
require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");
|
||||||
|
|
||||||
$comfourn = new CommandeFournisseur($db,"",$objectid);
|
if (!$comfournref)
|
||||||
$comfourn->fetch($objectid);
|
{
|
||||||
$client = new Societe($db);
|
$comfourn = new CommandeFournisseur($db,"",$comfournid);
|
||||||
$client->fetch($comfourn->socid);
|
$comfourn->fetch($comfournid);
|
||||||
|
$comfournref = $comfourn->ref;
|
||||||
|
$soc = new Societe($db);
|
||||||
|
$soc->fetch($comfourn->socid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ($conf->fournisseur->dir_output.'/commande')
|
if ($conf->fournisseur->dir_output.'/commande')
|
||||||
{
|
{
|
||||||
$comfournref = dol_sanitizeFileName($comfourn->ref);
|
$suppordref = dol_sanitizeFileName($comfournref);
|
||||||
$dir = $conf->commande->dir_output . "/" . $comfournref ;
|
$dir = $conf->fournisseur->dir_output . "/" . $suppordref ;
|
||||||
$file = $dir . "/" . $comfournref . ".pdf.png";
|
$file = $dir . "/" . $suppordref . ".pdf.png";
|
||||||
|
$multiple = $file . ".";
|
||||||
|
|
||||||
if ( file_exists( $file ) && is_writable( $file ) )
|
if ( file_exists( $file ) && is_writable( $file ) )
|
||||||
{
|
{
|
||||||
if ( ! dol_delete_file($file) )
|
if ( ! dol_delete_file($file,1) )
|
||||||
{
|
{
|
||||||
$this->error=$langs->trans("ErrorFailedToOpenFile",$file);
|
$this->error=$langs->trans("ErrorFailedToOpenFile",$file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for ($i = 0; $i < 20; $i++)
|
||||||
|
{
|
||||||
|
$preview = $multiple.$i;
|
||||||
|
|
||||||
|
if ( file_exists( $preview ) && is_writable( $preview ) )
|
||||||
|
{
|
||||||
|
if ( ! dol_delete_file($preview,1) )
|
||||||
|
{
|
||||||
|
$this->error=$langs->trans("ErrorFailedToOpenFile",$preview);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user