Qual: Uniformize code and fix a ton of bugs.

This commit is contained in:
Laurent Destailleur 2014-10-27 03:24:45 +01:00
parent 2b08417b77
commit 6f77dc83c4
12 changed files with 358 additions and 264 deletions

View File

@ -111,10 +111,14 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e
include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be include, not includ_once include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be include, not includ_once
// Action clone object // Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes') { if ($action == 'confirm_clone' && $confirm == 'yes')
if (1 == 0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) { {
if (1 == 0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers'))
{
setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors'); setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors');
} else { }
else
{
if ($object->id > 0) { if ($object->id > 0) {
$result = $object->createFromClone($socid); $result = $object->createFromClone($socid);
if ($result > 0) { if ($result > 0) {
@ -129,7 +133,8 @@ if ($action == 'confirm_clone' && $confirm == 'yes') {
} }
// Delete proposal // Delete proposal
else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->propal->supprimer) { else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->propal->supprimer)
{
$result = $object->delete($user); $result = $object->delete($user);
if ($result > 0) { if ($result > 0) {
header('Location: ' . DOL_URL_ROOT . '/comm/propal/list.php'); header('Location: ' . DOL_URL_ROOT . '/comm/propal/list.php');
@ -141,7 +146,8 @@ else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->prop
} }
// Remove line // Remove line
else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->propal->creer) { else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->propal->creer)
{
$result = $object->deleteline($lineid); $result = $object->deleteline($lineid);
// reorder lines // reorder lines
if ($result) if ($result)
@ -164,13 +170,17 @@ else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->
} }
// Validation // Validation
else if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->propal->valider) { else if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->propal->valider)
{
$result = $object->valid($user); $result = $object->valid($user);
if ($result >= 0) { if ($result >= 0)
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { {
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
{
// Define output language // Define output language
$outputlangs = $langs; $outputlangs = $langs;
if (! empty($conf->global->MAIN_MULTILANGS)) { if (! empty($conf->global->MAIN_MULTILANGS))
{
$outputlangs = new Translate("", $conf); $outputlangs = new Translate("", $conf);
$newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->thirdparty->default_lang); $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->thirdparty->default_lang);
$outputlangs->setDefaultLang($newlang); $outputlangs->setDefaultLang($newlang);
@ -185,7 +195,8 @@ else if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->pr
} }
} }
else if ($action == 'setdate' && $user->rights->propal->creer) { else if ($action == 'setdate' && $user->rights->propal->creer)
{
$datep = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); $datep = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
if (empty($datep)) { if (empty($datep)) {
@ -198,23 +209,29 @@ else if ($action == 'setdate' && $user->rights->propal->creer) {
if ($result < 0) if ($result < 0)
dol_print_error($db, $object->error); dol_print_error($db, $object->error);
} }
} else if ($action == 'setecheance' && $user->rights->propal->creer) { }
else if ($action == 'setecheance' && $user->rights->propal->creer)
{
$result = $object->set_echeance($user, dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear'])); $result = $object->set_echeance($user, dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear']));
if ($result < 0) if ($result < 0)
dol_print_error($db, $object->error); dol_print_error($db, $object->error);
} else if ($action == 'setdate_livraison' && $user->rights->propal->creer) { }
else if ($action == 'setdate_livraison' && $user->rights->propal->creer)
{
$result = $object->set_date_livraison($user, dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year'])); $result = $object->set_date_livraison($user, dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']));
if ($result < 0) if ($result < 0)
dol_print_error($db, $object->error); dol_print_error($db, $object->error);
} }
// Positionne ref client // Positionne ref client
else if ($action == 'set_ref_client' && $user->rights->propal->creer) { else if ($action == 'set_ref_client' && $user->rights->propal->creer)
{
$object->set_ref_client($user, $_POST['ref_client']); $object->set_ref_client($user, $_POST['ref_client']);
} }
// Create proposal // Create proposal
else if ($action == 'add' && $user->rights->propal->creer) { else if ($action == 'add' && $user->rights->propal->creer)
{
$object->socid = $socid; $object->socid = $socid;
$object->fetch_thirdparty(); $object->fetch_thirdparty();

View File

@ -1326,67 +1326,77 @@ class Propal extends CommonObject
{ {
$num = $this->ref; $num = $this->ref;
} }
$this->newref = $num;
$sql = "UPDATE ".MAIN_DB_PREFIX."propal"; $sql = "UPDATE ".MAIN_DB_PREFIX."propal";
$sql.= " SET ref = '".$num."',"; $sql.= " SET ref = '".$num."',";
$sql.= " fk_statut = 1, date_valid='".$this->db->idate($now)."', fk_user_valid=".$user->id; $sql.= " fk_statut = 1, date_valid='".$this->db->idate($now)."', fk_user_valid=".$user->id;
$sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0";
dol_syslog(get_class($this).'::valid', LOG_DEBUG); dol_syslog(get_class($this)."::valid", LOG_DEBUG);
if ($this->db->query($sql)) $resql=$this->db->query($sql);
if (! $resql)
{
dol_print_error($this->db);
$error++;
}
// Trigger calls
if (! $error && ! $notrigger)
{
// Call trigger
$result=$this->call_trigger('PROPAL_VALIDATE',$user);
if ($result < 0) { $error++; }
// End call triggers
}
if (! $error)
{ {
if (! $notrigger) $this->oldref = $this->ref;
{
// Call trigger
$result=$this->call_trigger('PROPAL_VALIDATE',$user);
if ($result < 0) { $error++; }
// End call triggers
}
if (! $error) // Rename directory if dir was a temporary ref
{ if (preg_match('/^[\(]?PROV/i', $this->ref))
// Rename directory if dir was a temporary ref {
if (preg_match('/^[\(]?PROV/i', $this->ref)) // Rename of propal directory ($this->ref = old ref, $num = new ref)
{ // to not lose the linked files
// Rename of propal directory ($this->ref = old ref, $num = new ref) $oldref = dol_sanitizeFileName($this->ref);
// to not lose the linked files $newref = dol_sanitizeFileName($num);
$oldref = dol_sanitizeFileName($this->ref); $dirsource = $conf->propal->dir_output.'/'.$oldref;
$newref = dol_sanitizeFileName($num); $dirdest = $conf->propal->dir_output.'/'.$newref;
$dirsource = $conf->propal->dir_output.'/'.$oldref;
$dirdest = $conf->propal->dir_output.'/'.$newref;
if (file_exists($dirsource))
{
dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest);
if (@rename($dirsource, $dirdest)) if (file_exists($dirsource))
{ {
dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest);
if (@rename($dirsource, $dirdest))
{
dol_syslog("Rename ok");
// Rename docs starting with $oldref with $newref
$listoffiles=dol_dir_list($conf->propal->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
foreach($listoffiles as $fileentry)
{
$dirsource=$fileentry['name'];
$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
$dirsource=$fileentry['path'].'/'.$dirsource;
$dirdest=$fileentry['path'].'/'.$dirdest;
@rename($dirsource, $dirdest);
}
}
}
}
dol_syslog("Rename ok"); $this->ref=$num;
// Deleting old PDF in new rep $this->brouillon=0;
dol_delete_file($conf->propal->dir_output.'/'.$newref.'/'.$oldref.'*.*'); $this->statut = 1;
} $this->user_valid_id=$user->id;
} $this->datev=$now;
}
$this->ref=$num; $this->db->commit();
$this->brouillon=0; return 1;
$this->statut = 1;
$this->user_valid_id=$user->id;
$this->datev=$now;
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -2;
}
} }
else else
{ {
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }
} }
} }

View File

@ -183,9 +183,10 @@ class Commande extends CommonOrder
* *
* @param User $user User making status change * @param User $user User making status change
* @param int $idwarehouse Id of warehouse to use for stock decrease * @param int $idwarehouse Id of warehouse to use for stock decrease
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
* @return int <=0 if OK, >0 if KO * @return int <=0 if OK, >0 if KO
*/ */
function valid($user, $idwarehouse=0) function valid($user, $idwarehouse=0, $notrigger=0)
{ {
global $conf,$langs; global $conf,$langs;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@ -223,9 +224,10 @@ class Commande extends CommonOrder
$num = $this->getNextNumRef($soc); $num = $this->getNextNumRef($soc);
} }
else else
{ {
$num = $this->ref; $num = $this->ref;
} }
$this->newref = $num;
// Validate // Validate
$sql = "UPDATE ".MAIN_DB_PREFIX."commande"; $sql = "UPDATE ".MAIN_DB_PREFIX."commande";
@ -273,43 +275,49 @@ class Commande extends CommonOrder
} }
} }
if (! $error && ! $notrigger)
{
// Call trigger
$result=$this->call_trigger('ORDER_VALIDATE',$user);
if ($result < 0) $error++;
// End call triggers
}
if (! $error) if (! $error)
{ {
$this->oldref=''; $this->oldref = $this->ref;
// Rename directory if dir was a temporary ref // Rename directory if dir was a temporary ref
if (preg_match('/^[\(]?PROV/i', $this->ref)) if (preg_match('/^[\(]?PROV/i', $this->ref))
{ {
// On renomme repertoire ($this->ref = ancienne ref, $numfa = nouvelle ref) // On renomme repertoire ($this->ref = ancienne ref, $numfa = nouvelle ref)
// in order not to lose the attachments // in order not to lose the attachments
$comref = dol_sanitizeFileName($this->ref); $oldref = dol_sanitizeFileName($this->ref);
$snum = dol_sanitizeFileName($num); $newref = dol_sanitizeFileName($num);
$dirsource = $conf->commande->dir_output.'/'.$comref; $dirsource = $conf->commande->dir_output.'/'.$oldref;
$dirdest = $conf->commande->dir_output.'/'.$snum; $dirdest = $conf->commande->dir_output.'/'.$newref;
if (file_exists($dirsource)) if (file_exists($dirsource))
{ {
dol_syslog(get_class($this)."::valid() rename dir ".$dirsource." into ".$dirdest); dol_syslog(get_class($this)."::valid() rename dir ".$dirsource." into ".$dirdest);
if (@rename($dirsource, $dirdest)) if (@rename($dirsource, $dirdest))
{ {
$this->oldref = $comref;
dol_syslog("Rename ok"); dol_syslog("Rename ok");
// Suppression ancien fichier PDF dans nouveau rep // Rename docs starting with $oldref with $newref
dol_delete_file($conf->commande->dir_output.'/'.$snum.'/'.$comref.'*.*'); $listoffiles=dol_dir_list($conf->commande->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
foreach($listoffiles as $fileentry)
{
$dirsource=$fileentry['name'];
$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
$dirsource=$fileentry['path'].'/'.$dirsource;
$dirdest=$fileentry['path'].'/'.$dirdest;
@rename($dirsource, $dirdest);
}
} }
} }
} }
} }
if (! $error)
{
// Call trigger
$result=$this->call_trigger('ORDER_VALIDATE',$user);
if ($result < 0) $error++;
// End call triggers
}
// Set new ref and current status // Set new ref and current status
if (! $error) if (! $error)
{ {
@ -323,7 +331,7 @@ class Commande extends CommonOrder
return 1; return 1;
} }
else else
{ {
$this->db->rollback(); $this->db->rollback();
return -1; return -1;
} }

View File

@ -1589,9 +1589,10 @@ class Facture extends CommonInvoice
* @param User $user Object user that validate * @param User $user Object user that validate
* @param string $force_number Reference to force on invoice * @param string $force_number Reference to force on invoice
* @param int $idwarehouse Id of warehouse to use for stock decrease * @param int $idwarehouse Id of warehouse to use for stock decrease
* @return int <0 if KO, >0 if OK * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
* @return int <0 if KO, >0 if OK
*/ */
function validate($user, $force_number='', $idwarehouse=0) function validate($user, $force_number='', $idwarehouse=0, $notrigger=0)
{ {
global $conf,$langs; global $conf,$langs;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@ -1679,6 +1680,7 @@ class Facture extends CommonInvoice
{ {
$num = $this->ref; $num = $this->ref;
} }
$this->newref = $num;
if ($num) if ($num)
{ {
@ -1738,45 +1740,50 @@ class Facture extends CommonInvoice
} }
} }
// Trigger calls
if (! $error && ! $notrigger)
{
// Call trigger
$result=$this->call_trigger('BILL_VALIDATE',$user);
if ($result < 0) $error++;
// End call triggers
}
if (! $error) if (! $error)
{ {
$this->oldref = ''; $this->oldref = $this->ref;
// Rename directory if dir was a temporary ref // Rename directory if dir was a temporary ref
if (preg_match('/^[\(]?PROV/i', $this->ref)) if (preg_match('/^[\(]?PROV/i', $this->ref))
{ {
// Rename of object directory ($this->ref = old ref, $num = new ref) // Rename of object directory ($this->ref = old ref, $num = new ref)
// to not lose the linked files // to not lose the linked files
$facref = dol_sanitizeFileName($this->ref); $oldref = dol_sanitizeFileName($this->ref);
$snumfa = dol_sanitizeFileName($num); $newref = dol_sanitizeFileName($num);
$dirsource = $conf->facture->dir_output.'/'.$facref; $dirsource = $conf->facture->dir_output.'/'.$oldref;
$dirdest = $conf->facture->dir_output.'/'.$snumfa; $dirdest = $conf->facture->dir_output.'/'.$newref;
if (file_exists($dirsource)) if (file_exists($dirsource))
{ {
dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest);
if (@rename($dirsource, $dirdest)) if (@rename($dirsource, $dirdest))
{ {
$this->oldref = $facref;
dol_syslog("Rename ok"); dol_syslog("Rename ok");
// Suppression ancien fichier PDF dans nouveau rep // Rename docs starting with $oldref with $newref
dol_delete_file($conf->facture->dir_output.'/'.$snumfa.'/'.$facref.'*.*'); $listoffiles=dol_dir_list($conf->facture->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
foreach($listoffiles as $fileentry)
{
$dirsource=$fileentry['name'];
$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
$dirsource=$fileentry['path'].'/'.$dirsource;
$dirdest=$fileentry['path'].'/'.$dirdest;
@rename($dirsource, $dirdest);
}
} }
} }
} }
} }
// Trigger calls
if (! $error)
{
// Call trigger
$result=$this->call_trigger('BILL_VALIDATE',$user);
if ($result < 0) $error++;
//TODO: Restoring ref, facnumber, statut, brouillon to previous value if trigger fail
// End call triggers
}
// Set new ref and define current statut // Set new ref and define current statut
if (! $error) if (! $error)
{ {

View File

@ -278,9 +278,10 @@ class Contrat extends CommonObject
* *
* @param User $user Objet User * @param User $user Objet User
* @param string $force_number Reference to force on contract (not implemented yet) * @param string $force_number Reference to force on contract (not implemented yet)
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function validate($user, $force_number='') function validate($user, $force_number='', $notrigger=0)
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
global $langs, $conf; global $langs, $conf;
@ -307,6 +308,7 @@ class Contrat extends CommonObject
{ {
$num = $this->ref; $num = $this->ref;
} }
$this->newref = $num;
if ($num) if ($num)
{ {
@ -323,30 +325,45 @@ class Contrat extends CommonObject
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
} }
// Trigger calls
if (! $error && ! $notrigger)
{
// Call trigger
$result=$this->call_trigger('CONTRACT_VALIDATE',$user);
if ($result < 0) { $error++; }
// End call triggers
}
if (! $error) if (! $error)
{ {
$this->oldref = ''; $this->oldref = $this->ref;
// Rename directory if dir was a temporary ref // Rename directory if dir was a temporary ref
if (preg_match('/^[\(]?PROV/i', $this->ref)) if (preg_match('/^[\(]?PROV/i', $this->ref))
{ {
// Rename of object directory ($this->ref = old ref, $num = new ref) // Rename of object directory ($this->ref = old ref, $num = new ref)
// to not lose the linked files // to not lose the linked files
$facref = dol_sanitizeFileName($this->ref); $oldref = dol_sanitizeFileName($this->ref);
$snumfa = dol_sanitizeFileName($num); $newref = dol_sanitizeFileName($num);
$dirsource = $conf->contract->dir_output.'/'.$facref; $dirsource = $conf->contract->dir_output.'/'.$oldref;
$dirdest = $conf->contract->dir_output.'/'.$snumfa; $dirdest = $conf->contract->dir_output.'/'.$newref;
if (file_exists($dirsource)) if (file_exists($dirsource))
{ {
dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest);
if (@rename($dirsource, $dirdest)) if (@rename($dirsource, $dirdest))
{ {
$this->oldref = $facref;
dol_syslog("Rename ok"); dol_syslog("Rename ok");
// Deleting old PDF in new rep // Rename docs starting with $oldref with $newref
dol_delete_file($conf->contract->dir_output.'/'.$snumfa.'/'.$facref.'*.*'); $listoffiles=dol_dir_list($conf->contract->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
foreach($listoffiles as $fileentry)
{
$dirsource=$fileentry['name'];
$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
$dirsource=$fileentry['path'].'/'.$dirsource;
$dirdest=$fileentry['path'].'/'.$dirdest;
@rename($dirsource, $dirdest);
}
} }
} }
} }
@ -360,15 +377,6 @@ class Contrat extends CommonObject
$this->brouillon=0; $this->brouillon=0;
$this->date_validation=$now; $this->date_validation=$now;
} }
// Trigger calls
if (! $error)
{
// Call trigger
$result=$this->call_trigger('CONTRACT_VALIDATE',$user);
if ($result < 0) { $error++; }
// End call triggers
}
} }
else else
{ {

View File

@ -139,6 +139,7 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil
$level1name=(isset($reg[1])?$reg[1]:''); $level1name=(isset($reg[1])?$reg[1]:'');
$file_list[] = array( $file_list[] = array(
"name" => $file, "name" => $file,
"path" => $path,
"level1name" => $level1name, "level1name" => $level1name,
"fullname" => $path.'/'.$file, "fullname" => $path.'/'.$file,
"date" => $filedate, "date" => $filedate,
@ -166,6 +167,7 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil
$level1name=(isset($reg[1])?$reg[1]:''); $level1name=(isset($reg[1])?$reg[1]:'');
$file_list[] = array( $file_list[] = array(
"name" => $file, "name" => $file,
"path" => $path,
"level1name" => $level1name, "level1name" => $level1name,
"fullname" => $path.'/'.$file, "fullname" => $path.'/'.$file,
"date" => $filedate, "date" => $filedate,

View File

@ -106,8 +106,8 @@ class InterfaceActionsAuto extends DolibarrTriggers
$langs->load("contracts"); $langs->load("contracts");
$object->actiontypecode='AC_OTH_AUTO'; $object->actiontypecode='AC_OTH_AUTO';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ContractValidatedInDolibarr",$object->ref); if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ContractValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg=$langs->transnoentities("ContractValidatedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("ContractValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0; $object->sendtoid=0;
@ -117,8 +117,8 @@ class InterfaceActionsAuto extends DolibarrTriggers
$langs->load("propal"); $langs->load("propal");
$object->actiontypecode='AC_OTH_AUTO'; $object->actiontypecode='AC_OTH_AUTO';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",$object->ref); if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg=$langs->transnoentities("PropalValidatedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0; $object->sendtoid=0;
@ -165,8 +165,8 @@ class InterfaceActionsAuto extends DolibarrTriggers
$langs->load("orders"); $langs->load("orders");
$object->actiontypecode='AC_OTH_AUTO'; $object->actiontypecode='AC_OTH_AUTO';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref); if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0; $object->sendtoid=0;
@ -192,8 +192,8 @@ class InterfaceActionsAuto extends DolibarrTriggers
$langs->load("bills"); $langs->load("bills");
$object->actiontypecode='AC_OTH_AUTO'; $object->actiontypecode='AC_OTH_AUTO';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref); if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0; $object->sendtoid=0;
@ -271,8 +271,8 @@ class InterfaceActionsAuto extends DolibarrTriggers
$langs->load("interventions"); $langs->load("interventions");
$object->actiontypecode='AC_OTH_AUTO'; $object->actiontypecode='AC_OTH_AUTO';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionValidatedInDolibarr",$object->ref); if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg=$langs->transnoentities("InterventionValidatedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("InterventionValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0; $object->sendtoid=0;
@ -337,10 +337,10 @@ class InterfaceActionsAuto extends DolibarrTriggers
$langs->load("sendings"); $langs->load("sendings");
$object->actiontypecode='AC_OTH_AUTO'; $object->actiontypecode='AC_OTH_AUTO';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingValidated",$object->ref); if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingValidated",($object->newref?$object->newref:$object->ref));
if (empty($object->actionmsg)) if (empty($object->actionmsg))
{ {
$object->actionmsg=$langs->transnoentities("ShippingValidated",$object->ref); $object->actionmsg=$langs->transnoentities("ShippingValidated",($object->newref?$object->newref:$object->ref));
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
} }
@ -368,8 +368,8 @@ class InterfaceActionsAuto extends DolibarrTriggers
$langs->load("orders"); $langs->load("orders");
$object->actiontypecode='AC_OTH_AUTO'; $object->actiontypecode='AC_OTH_AUTO';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref); if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0; $object->sendtoid=0;
@ -419,8 +419,8 @@ class InterfaceActionsAuto extends DolibarrTriggers
$langs->load("bills"); $langs->load("bills");
$object->actiontypecode='AC_OTH_AUTO'; $object->actiontypecode='AC_OTH_AUTO';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref); if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
$object->sendtoid=0; $object->sendtoid=0;
@ -474,8 +474,8 @@ class InterfaceActionsAuto extends DolibarrTriggers
$langs->load("members"); $langs->load("members");
$object->actiontypecode='AC_OTH_AUTO'; $object->actiontypecode='AC_OTH_AUTO';
if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref); if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("MemberValidatedInDolibarr",($object->newref?$object->newref:$object->ref));
$object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs);
$object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type;
$object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;

View File

@ -503,9 +503,10 @@ class Expedition extends CommonObject
* Validate object and update stock if option enabled * Validate object and update stock if option enabled
* *
* @param User $user Object user that validate * @param User $user Object user that validate
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
* @return int <0 if OK, >0 if KO * @return int <0 if OK, >0 if KO
*/ */
function valid($user) function valid($user, $notrigger=0)
{ {
global $conf, $langs; global $conf, $langs;
@ -547,6 +548,7 @@ class Expedition extends CommonObject
{ {
$numref = "EXP".$this->id; $numref = "EXP".$this->id;
} }
$this->newref = $numref;
$now=dol_now(); $now=dol_now();
@ -617,9 +619,17 @@ class Expedition extends CommonObject
} }
} }
if (! $error && ! $notrigger)
{
// Call trigger
$result=$this->call_trigger('SHIPPING_VALIDATE',$user);
if ($result < 0) { $error++; }
// End call triggers
}
if (! $error) if (! $error)
{ {
$this->oldref=''; $this->oldref = $this->ref;
// Rename directory if dir was a temporary ref // Rename directory if dir was a temporary ref
if (preg_match('/^[\(]?PROV/i', $this->ref)) if (preg_match('/^[\(]?PROV/i', $this->ref))
@ -636,11 +646,17 @@ class Expedition extends CommonObject
if (@rename($dirsource, $dirdest)) if (@rename($dirsource, $dirdest))
{ {
$this->oldref = $oldref; dol_syslog("Rename ok");
// Rename docs starting with $oldref with $newref
dol_syslog("Rename ok"); $listoffiles=dol_dir_list($conf->expedition->dir_output.'/sending/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
// Suppression ancien fichier PDF dans nouveau rep foreach($listoffiles as $fileentry)
dol_delete_file($dirdest.'/'.$oldref.'*.*'); {
$dirsource=$fileentry['name'];
$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
$dirsource=$fileentry['path'].'/'.$dirsource;
$dirdest=$fileentry['path'].'/'.$dirdest;
@rename($dirsource, $dirdest);
}
} }
} }
} }
@ -653,14 +669,6 @@ class Expedition extends CommonObject
$this->statut = 1; $this->statut = 1;
} }
if (! $error)
{
// Call trigger
$result=$this->call_trigger('SHIPPING_VALIDATE',$user);
if ($result < 0) { $error++; }
// End call triggers
}
if (! $error) if (! $error)
{ {
$this->db->commit(); $this->db->commit();

View File

@ -374,9 +374,10 @@ class Fichinter extends CommonObject
* Validate a intervention * Validate a intervention
* *
* @param User $user User that validate * @param User $user User that validate
* @return int <0 if KO, >0 if OK * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
* @return int <0 if KO, >0 if OK
*/ */
function setValid($user) function setValid($user, $notrigger=0)
{ {
global $conf; global $conf;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@ -398,6 +399,7 @@ class Fichinter extends CommonObject
{ {
$num = $this->ref; $num = $this->ref;
} }
$this->newref = $num;
$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter"; $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter";
$sql.= " SET fk_statut = 1"; $sql.= " SET fk_statut = 1";
@ -416,9 +418,17 @@ class Fichinter extends CommonObject
$error++; $error++;
} }
if (! $error && ! $notrigger)
{
// Call trigger
$result=$this->call_trigger('FICHINTER_VALIDATE',$user);
if ($result < 0) { $error++; }
// End call triggers
}
if (! $error) if (! $error)
{ {
$this->oldref = ''; $this->oldref = $this->ref;
// Rename directory if dir was a temporary ref // Rename directory if dir was a temporary ref
if (preg_match('/^[\(]?PROV/i', $this->ref)) if (preg_match('/^[\(]?PROV/i', $this->ref))
@ -426,20 +436,26 @@ class Fichinter extends CommonObject
// Rename of object directory ($this->ref = old ref, $num = new ref) // Rename of object directory ($this->ref = old ref, $num = new ref)
// to not lose the linked files // to not lose the linked files
$oldref = dol_sanitizeFileName($this->ref); $oldref = dol_sanitizeFileName($this->ref);
$snum = dol_sanitizeFileName($num); $newref = dol_sanitizeFileName($num);
$dirsource = $conf->ficheinter->dir_output.'/'.$oldref; $dirsource = $conf->ficheinter->dir_output.'/'.$oldref;
$dirdest = $conf->ficheinter->dir_output.'/'.$snum; $dirdest = $conf->ficheinter->dir_output.'/'.$newref;
if (file_exists($dirsource)) if (file_exists($dirsource))
{ {
dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); dol_syslog(get_class($this)."::setValid rename dir ".$dirsource." into ".$dirdest);
if (@rename($dirsource, $dirdest)) if (@rename($dirsource, $dirdest))
{ {
$this->oldref = $oldref; dol_syslog("Rename ok");
// Rename docs starting with $oldref with $newref
dol_syslog("Rename ok"); $listoffiles=dol_dir_list($conf->ficheinter->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
// Suppression ancien fichier PDF dans nouveau rep foreach($listoffiles as $fileentry)
dol_delete_file($conf->ficheinter->dir_output.'/'.$snum.'/'.$oldref.'*.*'); {
$dirsource=$fileentry['name'];
$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
$dirsource=$fileentry['path'].'/'.$dirsource;
$dirdest=$fileentry['path'].'/'.$dirdest;
@rename($dirsource, $dirdest);
}
} }
} }
} }
@ -454,14 +470,6 @@ class Fichinter extends CommonObject
$this->date_validation=$now; $this->date_validation=$now;
} }
if (! $error)
{
// Call trigger
$result=$this->call_trigger('FICHINTER_VALIDATE',$user);
if ($result < 0) { $error++; }
// End call triggers
}
if (! $error) if (! $error)
{ {
$this->db->commit(); $this->db->commit();

View File

@ -317,9 +317,10 @@ class CommandeFournisseur extends CommonOrder
* *
* @param User $user Validator User * @param User $user Validator User
* @param int $idwarehouse Id of warehouse to use for stock decrease * @param int $idwarehouse Id of warehouse to use for stock decrease
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function valid($user,$idwarehouse=0) function valid($user,$idwarehouse=0,$notrigger=0)
{ {
global $langs,$conf; global $langs,$conf;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
@ -342,12 +343,13 @@ class CommandeFournisseur extends CommonOrder
$num = $this->getNextNumRef($soc); $num = $this->getNextNumRef($soc);
} }
else else
{ {
$num = $this->ref; $num = $this->ref;
} }
$this->newref = $num;
$sql = 'UPDATE '.MAIN_DB_PREFIX."commande_fournisseur"; $sql = 'UPDATE '.MAIN_DB_PREFIX."commande_fournisseur";
$sql.= " SET ref='".$num."',"; $sql.= " SET ref='".$this->db->escape($num)."',";
$sql.= " fk_statut = 1,"; $sql.= " fk_statut = 1,";
$sql.= " date_valid='".$this->db->idate(dol_now())."',"; $sql.= " date_valid='".$this->db->idate(dol_now())."',";
$sql.= " fk_user_valid = ".$user->id; $sql.= " fk_user_valid = ".$user->id;
@ -361,9 +363,17 @@ class CommandeFournisseur extends CommonOrder
$error++; $error++;
} }
if (! $error && ! $notrigger)
{
// Call trigger
$result=$this->call_trigger('ORDER_SUPPLIER_VALIDATE',$user);
if ($result < 0) $error++;
// End call triggers
}
if (! $error) if (! $error)
{ {
$this->oldref=''; $this->oldref = $this->ref;
// Rename directory if dir was a temporary ref // Rename directory if dir was a temporary ref
if (preg_match('/^[\(]?PROV/i', $this->ref)) if (preg_match('/^[\(]?PROV/i', $this->ref))
@ -380,11 +390,17 @@ class CommandeFournisseur extends CommonOrder
if (@rename($dirsource, $dirdest)) if (@rename($dirsource, $dirdest))
{ {
$this->oldref = $oldref;
dol_syslog("Rename ok"); dol_syslog("Rename ok");
// Suppression ancien fichier PDF dans nouveau rep // Rename docs starting with $oldref with $newref
dol_delete_file($dirdest.'/'.$oldref.'*.*'); $listoffiles=dol_dir_list($conf->fournisseur->dir_output.'/commande/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
foreach($listoffiles as $fileentry)
{
$dirsource=$fileentry['name'];
$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
$dirsource=$fileentry['path'].'/'.$dirsource;
$dirdest=$fileentry['path'].'/'.$dirdest;
@rename($dirsource, $dirdest);
}
} }
} }
} }
@ -397,18 +413,6 @@ class CommandeFournisseur extends CommonOrder
$this->ref = $num; $this->ref = $num;
} }
if (! $error)
{
// Call trigger
$result=$this->call_trigger('ORDER_SUPPLIER_VALIDATE',$user);
if ($result < 0)
{
$this->db->rollback();
return -1;
}
// End call triggers
}
if (! $error) if (! $error)
{ {
$this->db->commit(); $this->db->commit();
@ -619,9 +623,10 @@ class CommandeFournisseur extends CommonOrder
$num = $this->getNextNumRef($soc); $num = $this->getNextNumRef($soc);
} }
else else
{ {
$num = $this->ref; $num = $this->ref;
} }
$this->newref = $num;
$sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur";
$sql.= " SET ref='".$this->db->escape($num)."',"; $sql.= " SET ref='".$this->db->escape($num)."',";

View File

@ -852,9 +852,10 @@ class FactureFournisseur extends CommonInvoice
* @param User $user Object user that validate * @param User $user Object user that validate
* @param string $force_number Reference to force on invoice * @param string $force_number Reference to force on invoice
* @param int $idwarehouse Id of warehouse for stock change * @param int $idwarehouse Id of warehouse for stock change
* @param int $notrigger 1=Does not execute triggers, 0= execuete triggers
* @return int <0 if KO, =0 if nothing to do, >0 if OK * @return int <0 if KO, =0 if nothing to do, >0 if OK
*/ */
function validate($user, $force_number='', $idwarehouse=0) function validate($user, $force_number='', $idwarehouse=0, $notrigger=0)
{ {
global $conf,$langs; global $conf,$langs;
@ -886,9 +887,10 @@ class FactureFournisseur extends CommonInvoice
$num = $this->getNextNumRef($this->client); $num = $this->getNextNumRef($this->client);
} }
else else
{ {
$num = $this->ref; $num = $this->ref;
} }
$this->newref = $num;
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn"; $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn";
$sql.= " SET ref='".$num."', fk_statut = 1, fk_user_valid = ".$user->id; $sql.= " SET ref='".$num."', fk_statut = 1, fk_user_valid = ".$user->id;
@ -920,31 +922,46 @@ class FactureFournisseur extends CommonInvoice
} }
} }
// Triggers call
if (! $error && $notrigger)
{
// Call trigger
$result=$this->call_trigger('BILL_SUPPLIER_VALIDATE',$user);
if ($result < 0) $error++;
// End call triggers
}
if (! $error) if (! $error)
{ {
$this->oldref = ''; $this->oldref = $this->ref;
// Rename directory if dir was a temporary ref // Rename directory if dir was a temporary ref
if (preg_match('/^[\(]?PROV/i', $this->ref)) if (preg_match('/^[\(]?PROV/i', $this->ref))
{ {
// On renomme repertoire facture ($this->ref = ancienne ref, $num = nouvelle ref) // On renomme repertoire facture ($this->ref = ancienne ref, $num = nouvelle ref)
// in order not to lose the attached files // in order not to lose the attached files
$facref = dol_sanitizeFileName($this->ref); $oldref = dol_sanitizeFileName($this->ref);
$snumfa = dol_sanitizeFileName($num); $newref = dol_sanitizeFileName($num);
$dirsource = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2).$facref; $dirsource = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2).$oldref;
$dirdest = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2).$snumfa; $dirdest = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2).$newref;
if (file_exists($dirsource)) if (file_exists($dirsource))
{ {
dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest);
if (@rename($dirsource, $dirdest)) if (@rename($dirsource, $dirdest))
{ {
$this->oldref = $facref;
dol_syslog("Rename ok"); dol_syslog("Rename ok");
// Suppression ancien fichier PDF dans nouveau rep // Rename docs starting with $oldref with $newref
dol_delete_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2).$snumfa.'/'.$facref.'*.*'); $listoffiles=dol_dir_list($conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2).$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
foreach($listoffiles as $fileentry)
{
$dirsource=$fileentry['name'];
$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
$dirsource=$fileentry['path'].'/'.$dirsource;
$dirdest=$fileentry['path'].'/'.$dirdest;
@rename($dirsource, $dirdest);
}
} }
} }
} }
@ -958,15 +975,6 @@ class FactureFournisseur extends CommonInvoice
//$this->date_validation=$now; this is stored into log table //$this->date_validation=$now; this is stored into log table
} }
// Triggers call
if (! $error)
{
// Call trigger
$result=$this->call_trigger('BILL_SUPPLIER_VALIDATE',$user);
if ($result < 0) $error++;
// End call triggers
}
if (! $error) if (! $error)
{ {
$this->db->commit(); $this->db->commit();

View File

@ -359,18 +359,21 @@ class Livraison extends CommonObject
$soc = new Societe($this->db); $soc = new Societe($this->db);
$soc->fetch($this->socid); $soc->fetch($this->socid);
// on verifie si le bon de livraison est en numerotation provisoire if (preg_match('/^[\(]?PROV/i', $this->ref))
$livref = substr($this->ref, 1, 4); {
if ($livref == 'PROV') $numref = $objMod->livraison_get_num($soc,$this);
}
else
{ {
$numref = $objMod->livraison_get_num($soc,$this); $numref = $this->ref;
} }
$this->newref = $numref;
// Tester si non deja au statut valide. Si oui, on arrete afin d'eviter // Tester si non deja au statut valide. Si oui, on arrete afin d'eviter
// de decrementer 2 fois le stock. // de decrementer 2 fois le stock.
$sql = "SELECT ref"; $sql = "SELECT ref";
$sql.= " FROM ".MAIN_DB_PREFIX."livraison"; $sql.= " FROM ".MAIN_DB_PREFIX."livraison";
$sql.= " WHERE ref = '".$numref."'"; $sql.= " WHERE ref = '".$this->db->escape($numref)."'";
$sql.= " AND fk_statut <> 0"; $sql.= " AND fk_statut <> 0";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
@ -393,10 +396,24 @@ class Livraison extends CommonObject
$sql.= " AND fk_statut = 0"; $sql.= " AND fk_statut = 0";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if (! $resql)
{ {
dol_print_error($this->db);
$this->error=$this->db->lasterror();
$error++;
}
$this->oldref=''; if (! $error && ! $notrigger)
{
// Call trigger
$result=$this->call_trigger('DELIVERY_VALIDATE',$user);
if ($result < 0) $error++;
// End call triggers
}
if (! $error)
{
$this->oldref = $this->ref;
// Rename directory if dir was a temporary ref // Rename directory if dir was a temporary ref
if (preg_match('/^[\(]?PROV/i', $this->ref)) if (preg_match('/^[\(]?PROV/i', $this->ref))
@ -413,11 +430,17 @@ class Livraison extends CommonObject
if (@rename($dirsource, $dirdest)) if (@rename($dirsource, $dirdest))
{ {
$this->oldref = $oldref; dol_syslog("Rename ok");
// Rename docs starting with $oldref with $newref
dol_syslog("Rename ok"); $listoffiles=dol_dir_list($conf->expedition->dir_output.'/receipt/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/'));
// Suppression ancien fichier PDF dans nouveau rep foreach($listoffiles as $fileentry)
dol_delete_file($dirdest.'/'.$oldref.'*.*'); {
$dirsource=$fileentry['name'];
$dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource);
$dirsource=$fileentry['path'].'/'.$dirsource;
$dirdest=$fileentry['path'].'/'.$dirdest;
@rename($dirsource, $dirdest);
}
} }
} }
} }
@ -431,12 +454,17 @@ class Livraison extends CommonObject
dol_syslog(get_class($this)."::valid ok"); dol_syslog(get_class($this)."::valid ok");
} }
else
if (! $error)
{
$this->db->commit();
return 1;
}
else
{ {
$this->db->rollback(); $this->db->rollback();
$this->error=$this->db->error()." - sql=$sql"; return -1;
return -1; }
}
} }
} }
} }
@ -446,21 +474,6 @@ class Livraison extends CommonObject
dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
return -1; return -1;
} }
// Call trigger
$result=$this->call_trigger('DELIVERY_VALIDATE',$user);
// End call triggers
if ($result < 0)
{
$this->db->rollback();
dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
return -1;
}
else
{
$this->db->commit();
return 1;
}
} }
/** /**