Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2012-08-05 21:14:52 +02:00
commit cc76ea1f66
8 changed files with 143 additions and 68 deletions

View File

@ -798,7 +798,8 @@ function dol_delete_preview($object)
if ($object->element == 'order_supplier') $dir = $conf->fournisseur->dir_output.'/commande';
elseif ($object->element == 'invoice_supplier') $dir = $conf->fournisseur->dir_output.'/facture';
elseif ($object->element == 'project') $dir = $conf->projet->dir_output;
elseif ($object->element == 'delivery') $dir = $conf->livraison->dir_output;
elseif ($object->element == 'shipping') $dir = $conf->expedition->dir_output.'/sending';
elseif ($object->element == 'delivery') $dir = $conf->expedition->dir_output.'/receipt';
if (empty($dir)) return 'ErrorObjectNoSupportedByFunction';

View File

@ -150,7 +150,7 @@ abstract class ModelNumRefExpedition
*/
function expedition_pdf_create($db, $object, $modele, $outputlangs)
{
global $conf,$langs;
global $conf,$user,$langs;
$langs->load("sendings");
@ -220,6 +220,16 @@ function expedition_pdf_create($db, $object, $modele, $outputlangs)
// we delete preview files
//require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
//dol_delete_preview($object);
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($db);
$result=$interface->run_triggers('SHIPPING_BUILDDOC',$object,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
return 1;
}
else

View File

@ -156,7 +156,7 @@ abstract class ModeleNumRefDeliveryOrder
*/
function delivery_order_pdf_create($db, $object, $modele, $outputlangs='')
{
global $conf,$langs;
global $conf,$user,$langs;
$langs->load("deliveries");
@ -224,6 +224,16 @@ function delivery_order_pdf_create($db, $object, $modele, $outputlangs='')
// we delete preview files
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
dol_delete_preview($object);
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($db);
$result=$interface->run_triggers('DELIVERY_BUILDDOC',$object,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
return 1;
}
else

View File

@ -262,6 +262,10 @@ class InterfaceDemo
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
elseif ($action == 'SUPPLIER_ORDER_BUILDDOC')
{
dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
}
// Proposals
elseif ($action == 'PROPAL_CREATE')

View File

@ -539,26 +539,30 @@ class Expedition extends CommonObject
if (! $error)
{
// On efface le repertoire de pdf provisoire
$expeditionref = dol_sanitizeFileName($this->ref);
if ($conf->expedition->dir_output)
{
$dir = $conf->expedition->dir_output . "/" . $expeditionref;
$file = $dir . "/" . $expeditionref . ".pdf";
if (file_exists($file))
{
if (!dol_delete_file($file))
{
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
}
}
if (file_exists($dir))
{
if (!dol_delete_dir($dir))
{
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
}
}
$this->oldref='';
// Rename directory if dir was a temporary ref
if (preg_match('/^[\(]?PROV/i', $this->ref))
{
// On renomme repertoire ($this->ref = ancienne ref, $numfa = nouvelle ref)
// afin de ne pas perdre les fichiers attaches
$oldref = dol_sanitizeFileName($this->ref);
$newref = dol_sanitizeFileName($numref);
$dirsource = $conf->expedition->dir_output.'/sending/'.$oldref;
$dirdest = $conf->expedition->dir_output.'/sending/'.$newref;
if (file_exists($dirsource))
{
dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest);
if (@rename($dirsource, $dirdest))
{
$this->oldref = $oldref;
dol_syslog("Rename ok");
// Suppression ancien fichier PDF dans nouveau rep
dol_delete_file($dirdest.'/'.$oldref.'.*');
}
}
}
}
@ -787,11 +791,11 @@ class Expedition extends CommonObject
$this->db->commit();
// On efface le repertoire de pdf provisoire
$expref = dol_sanitizeFileName($this->ref);
if ($conf->expedition->dir_output)
$ref = dol_sanitizeFileName($this->ref);
if (! empty($conf->expedition->dir_output))
{
$dir = $conf->expedition->dir_output . "/" . $expref ;
$file = $conf->expedition->dir_output . "/" . $expref . "/" . $expref . ".pdf";
$dir = $conf->expedition->dir_output . '/sending/' . $ref ;
$file = $dir . '/' . $ref . '.pdf';
if (file_exists($file))
{
if (! dol_delete_file($file))

View File

@ -214,6 +214,7 @@ else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->exped
else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer)
{
$object->fetch($id);
$object->fetch_thirdparty();
$result = $object->delete();
if ($result > 0)
{
@ -285,13 +286,9 @@ else if ($action == 'settrackingnumber' || $action == 'settrackingurl'
$action="";
}
/*
* Build doc
*/
// Build document
else if ($action == 'builddoc') // En get ou en post
{
// Sauvegarde le dernier modele choisi pour generer un document
$shipment = new Expedition($db);
$shipment->fetch($id);
@ -320,6 +317,23 @@ else if ($action == 'builddoc') // En get ou en post
}
}
// Delete file in doc form
elseif ($action == 'remove_file')
{
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
$object = new Expedition($db);
if ($object->fetch($id))
{
$object->fetch_thirdparty();
$upload_dir = $conf->expedition->dir_output . "/sending";
$file = $upload_dir . '/' . GETPOST('file');
$ret=dol_delete_file($file,0,0,0,$object);
if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
}
}
/*
* Add file in email form
*/

View File

@ -289,9 +289,6 @@ class Livraison extends CommonObject
if ($this->statut == 0) $this->brouillon = 1;
$file = $conf->livraison->dir_output . "/" .get_exdir($livraison->id,2) . "/" . $this->id.".pdf";
$this->pdf_filename = $file;
/*
* Lignes
*/
@ -357,14 +354,14 @@ class Livraison extends CommonObject
$livref = substr($this->ref, 1, 4);
if ($livref == 'PROV')
{
$this->ref = $objMod->livraison_get_num($soc,$this);
$numref = $objMod->livraison_get_num($soc,$this);
}
// Tester si non deja au statut valide. Si oui, on arrete afin d'eviter
// de decrementer 2 fois le stock.
$sql = "SELECT ref";
$sql.= " FROM ".MAIN_DB_PREFIX."livraison";
$sql.= " WHERE ref = '".$this->ref."'";
$sql.= " WHERE ref = '".$numref."'";
$sql.= " AND fk_statut <> 0";
$sql.= " AND entity = ".$conf->entity;
@ -379,7 +376,7 @@ class Livraison extends CommonObject
}
$sql = "UPDATE ".MAIN_DB_PREFIX."livraison SET";
$sql.= " ref='".$this->db->escape($this->ref)."'";
$sql.= " ref='".$this->db->escape($numref)."'";
$sql.= ", fk_statut = 1";
$sql.= ", date_valid = ".$this->db->idate($now);
$sql.= ", fk_user_valid = ".$user->id;
@ -389,28 +386,31 @@ class Livraison extends CommonObject
$resql=$this->db->query($sql);
if ($resql)
{
// On efface le repertoire de pdf provisoire
$numref = dol_sanitizeFileName($this->ref);
if ($conf->expedition->dir_output)
{
$dir = $conf->livraison->dir_output . "/" . $numref ;
$file = $dir . "/" . $numref . ".pdf";
if (file_exists($file))
{
if (! dol_delete_file($file))
{
$this->error=$langs->trans("ErrorCanNotDeleteFile",$file);
return 0;
}
}
if (file_exists($dir))
{
if (! dol_delete_dir($dir))
{
$this->error=$langs->trans("ErrorCanNotDeleteDir",$dir);
return 0;
}
}
$this->oldref='';
// Rename directory if dir was a temporary ref
if (preg_match('/^[\(]?PROV/i', $this->ref))
{
// On renomme repertoire ($this->ref = ancienne ref, $numfa = nouvelle ref)
// afin de ne pas perdre les fichiers attaches
$oldref = dol_sanitizeFileName($this->ref);
$newref = dol_sanitizeFileName($numref);
$dirsource = $conf->expedition->dir_output.'/receipt/'.$oldref;
$dirdest = $conf->expedition->dir_output.'/receipt/'.$newref;
if (file_exists($dirsource))
{
dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest);
if (@rename($dirsource, $dirdest))
{
$this->oldref = $oldref;
dol_syslog("Rename ok");
// Suppression ancien fichier PDF dans nouveau rep
dol_delete_file($dirdest.'/'.$oldref.'.*');
}
}
}
// Set new ref and current status
@ -550,6 +550,8 @@ class Livraison extends CommonObject
*/
function delete()
{
global $conf, $langs, $user;
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
$this->db->begin();
@ -567,16 +569,16 @@ class Livraison extends CommonObject
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."livraison";
$sql.= " WHERE rowid = ".$this->id;
if ( $this->db->query($sql) )
if ($this->db->query($sql))
{
$this->db->commit();
// On efface le repertoire de pdf provisoire
$livref = dol_sanitizeFileName($this->ref);
if ($conf->livraison->dir_output)
$ref = dol_sanitizeFileName($this->ref);
if (! empty($conf->expedition->dir_output))
{
$dir = $conf->livraison->dir_output . "/" . $livref ;
$file = $conf->livraison->dir_output . "/" . $livref . "/" . $livref . ".pdf";
$dir = $conf->expedition->dir_output . '/receipt/' . $ref ;
$file = $dir . '/' . $ref . '.pdf';
if (file_exists($file))
{
if (!dol_delete_file($file))
@ -594,6 +596,15 @@ class Livraison extends CommonObject
}
}
// Call triggers
include_once(DOL_DOCUMENT_ROOT."/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('DELIVERY_DELETE',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// End call triggers
return 1;
}
else

View File

@ -40,6 +40,8 @@ $langs->load("sendings");
$langs->load("bills");
$langs->load('deliveries');
$action=GETPOST('action', 'alpha');
// Security check
$id = isset($_GET["id"])?$_GET["id"]:'';
if ($user->societe_id) $socid=$user->societe_id;
@ -133,6 +135,7 @@ if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes' &&
{
$object = new Livraison($db);
$object->fetch($_GET["id"]);
$object->fetch_thirdparty();
$db->begin();
$result=$object->delete();
@ -156,6 +159,7 @@ if ($_REQUEST['action'] == 'builddoc') // En get ou en post
{
$object = new Livraison($db);
$object->fetch($_REQUEST['id']);
$object->fetch_thirdparty();
if ($_REQUEST['model'])
{
@ -184,6 +188,23 @@ if ($_REQUEST['action'] == 'builddoc') // En get ou en post
}
}
// Delete file in doc form
elseif ($action == 'remove_file')
{
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
$object = new Livraison($db);
if ($object->fetch($id))
{
$object->fetch_thirdparty();
$upload_dir = $conf->expedition->dir_output . "/receipt";
$file = $upload_dir . '/' . GETPOST('file');
$ret=dol_delete_file($file,0,0,0,$object);
if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
}
}
/*
* View
@ -321,7 +342,7 @@ if ($_GET["action"] == 'create')
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
$label = (! empty($product->multilangs[$outputlangs->defaultlang]["libelle"])) ? $product->multilangs[$outputlangs->defaultlang]["libelle"] : $product->libelle;
}
else
@ -551,7 +572,7 @@ else
// Define output language
if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
{
{
$delivery->fetch_thirdparty();
$outputlangs = $langs;
$newlang='';
@ -562,7 +583,7 @@ else
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
$label = (! empty($product->multilangs[$outputlangs->defaultlang]["libelle"])) ? $product->multilangs[$outputlangs->defaultlang]["libelle"] : $delivery->lines[$i]->product_label;
}
else