diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 5d1db5cf7d1..07cad40be7a 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -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 // Action clone object -if ($action == 'confirm_clone' && $confirm == 'yes') { - if (1 == 0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) { +if ($action == 'confirm_clone' && $confirm == 'yes') +{ + if (1 == 0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) + { setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors'); - } else { + } + else + { if ($object->id > 0) { $result = $object->createFromClone($socid); if ($result > 0) { @@ -129,7 +133,8 @@ if ($action == 'confirm_clone' && $confirm == 'yes') { } // 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); if ($result > 0) { 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 -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); // reorder lines if ($result) @@ -164,13 +170,17 @@ else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights-> } // 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); - if ($result >= 0) { - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { + if ($result >= 0) + { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { // Define output language $outputlangs = $langs; - if (! empty($conf->global->MAIN_MULTILANGS)) { + if (! empty($conf->global->MAIN_MULTILANGS)) + { $outputlangs = new Translate("", $conf); $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->thirdparty->default_lang); $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']); if (empty($datep)) { @@ -198,23 +209,29 @@ else if ($action == 'setdate' && $user->rights->propal->creer) { if ($result < 0) 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'])); if ($result < 0) 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'])); if ($result < 0) dol_print_error($db, $object->error); } // 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']); } // Create proposal -else if ($action == 'add' && $user->rights->propal->creer) { +else if ($action == 'add' && $user->rights->propal->creer) +{ $object->socid = $socid; $object->fetch_thirdparty(); diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index cdd5618c6b7..c056e5aa1c5 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -1326,67 +1326,77 @@ class Propal extends CommonObject { $num = $this->ref; } + $this->newref = $num; $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; $sql.= " SET ref = '".$num."',"; $sql.= " fk_statut = 1, date_valid='".$this->db->idate($now)."', fk_user_valid=".$user->id; $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; - dol_syslog(get_class($this).'::valid', LOG_DEBUG); - if ($this->db->query($sql)) + dol_syslog(get_class($this)."::valid", LOG_DEBUG); + $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) - { - // Call trigger - $result=$this->call_trigger('PROPAL_VALIDATE',$user); - if ($result < 0) { $error++; } - // End call triggers - } + $this->oldref = $this->ref; - if (! $error) - { - // 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 - $oldref = dol_sanitizeFileName($this->ref); - $newref = dol_sanitizeFileName($num); - $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); + // 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 + $oldref = dol_sanitizeFileName($this->ref); + $newref = dol_sanitizeFileName($num); + $dirsource = $conf->propal->dir_output.'/'.$oldref; + $dirdest = $conf->propal->dir_output.'/'.$newref; - 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"); - // Deleting old PDF in new rep - dol_delete_file($conf->propal->dir_output.'/'.$newref.'/'.$oldref.'*.*'); - } - } - } + $this->ref=$num; + $this->brouillon=0; + $this->statut = 1; + $this->user_valid_id=$user->id; + $this->datev=$now; - $this->ref=$num; - $this->brouillon=0; - $this->statut = 1; - $this->user_valid_id=$user->id; - $this->datev=$now; - - $this->db->commit(); - return 1; - } - else - { - $this->db->rollback(); - return -2; - } + $this->db->commit(); + return 1; } else { - $this->db->rollback(); - return -1; + $this->db->rollback(); + return -1; } } } diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 6db8af5c2db..ce3ec431180 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -183,9 +183,10 @@ class Commande extends CommonOrder * * @param User $user User making status change * @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 */ - function valid($user, $idwarehouse=0) + function valid($user, $idwarehouse=0, $notrigger=0) { global $conf,$langs; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -223,9 +224,10 @@ class Commande extends CommonOrder $num = $this->getNextNumRef($soc); } else - { + { $num = $this->ref; } + $this->newref = $num; // Validate $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) { - $this->oldref=''; + $this->oldref = $this->ref; // 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) + // On renomme repertoire ($this->ref = ancienne ref, $numfa = nouvelle ref) // in order not to lose the attachments - $comref = dol_sanitizeFileName($this->ref); - $snum = dol_sanitizeFileName($num); - $dirsource = $conf->commande->dir_output.'/'.$comref; - $dirdest = $conf->commande->dir_output.'/'.$snum; + $oldref = dol_sanitizeFileName($this->ref); + $newref = dol_sanitizeFileName($num); + $dirsource = $conf->commande->dir_output.'/'.$oldref; + $dirdest = $conf->commande->dir_output.'/'.$newref; if (file_exists($dirsource)) { dol_syslog(get_class($this)."::valid() rename dir ".$dirsource." into ".$dirdest); if (@rename($dirsource, $dirdest)) { - $this->oldref = $comref; - dol_syslog("Rename ok"); - // Suppression ancien fichier PDF dans nouveau rep - dol_delete_file($conf->commande->dir_output.'/'.$snum.'/'.$comref.'*.*'); + // Rename docs starting with $oldref with $newref + $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 if (! $error) { @@ -323,7 +331,7 @@ class Commande extends CommonOrder return 1; } else - { + { $this->db->rollback(); return -1; } @@ -904,7 +912,7 @@ class Commande extends CommonOrder $modCommande = new $obj; $this->ref = $modCommande->getNextValue($objsoc,$this); - + // Create clone $result=$this->create($user); if ($result < 0) $error++; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index e07881d73db..605d4920669 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1589,9 +1589,10 @@ class Facture extends CommonInvoice * @param User $user Object user that validate * @param string $force_number Reference to force on invoice * @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; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -1679,6 +1680,7 @@ class Facture extends CommonInvoice { $num = $this->ref; } + $this->newref = $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) { - $this->oldref = ''; + $this->oldref = $this->ref; // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { // Rename of object directory ($this->ref = old ref, $num = new ref) // to not lose the linked files - $facref = dol_sanitizeFileName($this->ref); - $snumfa = dol_sanitizeFileName($num); - $dirsource = $conf->facture->dir_output.'/'.$facref; - $dirdest = $conf->facture->dir_output.'/'.$snumfa; + $oldref = dol_sanitizeFileName($this->ref); + $newref = dol_sanitizeFileName($num); + $dirsource = $conf->facture->dir_output.'/'.$oldref; + $dirdest = $conf->facture->dir_output.'/'.$newref; if (file_exists($dirsource)) { dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); if (@rename($dirsource, $dirdest)) { - $this->oldref = $facref; - dol_syslog("Rename ok"); - // Suppression ancien fichier PDF dans nouveau rep - dol_delete_file($conf->facture->dir_output.'/'.$snumfa.'/'.$facref.'*.*'); + // Rename docs starting with $oldref with $newref + $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 if (! $error) { diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 998ffada993..5626719d96d 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -278,9 +278,10 @@ class Contrat extends CommonObject * * @param User $user Objet User * @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 */ - function validate($user, $force_number='') + function validate($user, $force_number='', $notrigger=0) { require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; global $langs, $conf; @@ -307,6 +308,7 @@ class Contrat extends CommonObject { $num = $this->ref; } + $this->newref = $num; if ($num) { @@ -323,30 +325,45 @@ class Contrat extends CommonObject $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) { - $this->oldref = ''; + $this->oldref = $this->ref; // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { // Rename of object directory ($this->ref = old ref, $num = new ref) // to not lose the linked files - $facref = dol_sanitizeFileName($this->ref); - $snumfa = dol_sanitizeFileName($num); - $dirsource = $conf->contract->dir_output.'/'.$facref; - $dirdest = $conf->contract->dir_output.'/'.$snumfa; + $oldref = dol_sanitizeFileName($this->ref); + $newref = dol_sanitizeFileName($num); + $dirsource = $conf->contract->dir_output.'/'.$oldref; + $dirdest = $conf->contract->dir_output.'/'.$newref; if (file_exists($dirsource)) { dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); if (@rename($dirsource, $dirdest)) { - $this->oldref = $facref; - dol_syslog("Rename ok"); - // Deleting old PDF in new rep - dol_delete_file($conf->contract->dir_output.'/'.$snumfa.'/'.$facref.'*.*'); + // Rename docs starting with $oldref with $newref + $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->date_validation=$now; } - - // Trigger calls - if (! $error) - { - // Call trigger - $result=$this->call_trigger('CONTRACT_VALIDATE',$user); - if ($result < 0) { $error++; } - // End call triggers - } } else { diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index f85d1c8f4af..4b9e7eb520f 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -139,6 +139,7 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil $level1name=(isset($reg[1])?$reg[1]:''); $file_list[] = array( "name" => $file, + "path" => $path, "level1name" => $level1name, "fullname" => $path.'/'.$file, "date" => $filedate, @@ -166,6 +167,7 @@ function dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefil $level1name=(isset($reg[1])?$reg[1]:''); $file_list[] = array( "name" => $file, + "path" => $path, "level1name" => $level1name, "fullname" => $path.'/'.$file, "date" => $filedate, diff --git a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php index ffe539ff241..632acf71b0e 100644 --- a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php +++ b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php @@ -106,8 +106,8 @@ class InterfaceActionsAuto extends DolibarrTriggers $langs->load("contracts"); $object->actiontypecode='AC_OTH_AUTO'; - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ContractValidatedInDolibarr",$object->ref); - $object->actionmsg=$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->newref?$object->newref:$object->ref)); $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; @@ -117,8 +117,8 @@ class InterfaceActionsAuto extends DolibarrTriggers $langs->load("propal"); $object->actiontypecode='AC_OTH_AUTO'; - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",$object->ref); - $object->actionmsg=$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->newref?$object->newref:$object->ref)); $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; @@ -165,8 +165,8 @@ class InterfaceActionsAuto extends DolibarrTriggers $langs->load("orders"); $object->actiontypecode='AC_OTH_AUTO'; - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref); - $object->actionmsg=$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->newref?$object->newref:$object->ref)); $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; @@ -192,8 +192,8 @@ class InterfaceActionsAuto extends DolibarrTriggers $langs->load("bills"); $object->actiontypecode='AC_OTH_AUTO'; - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref); - $object->actionmsg=$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->newref?$object->newref:$object->ref)); $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; @@ -271,8 +271,8 @@ class InterfaceActionsAuto extends DolibarrTriggers $langs->load("interventions"); $object->actiontypecode='AC_OTH_AUTO'; - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionValidatedInDolibarr",$object->ref); - $object->actionmsg=$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->newref?$object->newref:$object->ref)); $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; @@ -337,10 +337,10 @@ class InterfaceActionsAuto extends DolibarrTriggers $langs->load("sendings"); $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)) { - $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; } @@ -368,8 +368,8 @@ class InterfaceActionsAuto extends DolibarrTriggers $langs->load("orders"); $object->actiontypecode='AC_OTH_AUTO'; - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref); - $object->actionmsg=$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->newref?$object->newref:$object->ref)); $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; @@ -419,8 +419,8 @@ class InterfaceActionsAuto extends DolibarrTriggers $langs->load("bills"); $object->actiontypecode='AC_OTH_AUTO'; - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref); - $object->actionmsg=$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->newref?$object->newref:$object->ref)); $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; @@ -474,8 +474,8 @@ class InterfaceActionsAuto extends DolibarrTriggers $langs->load("members"); $object->actiontypecode='AC_OTH_AUTO'; - if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref); - $object->actionmsg=$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->newref?$object->newref:$object->ref)); $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index c3d3d193bca..bb34f480d97 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -503,9 +503,10 @@ class Expedition extends CommonObject * Validate object and update stock if option enabled * * @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 */ - function valid($user) + function valid($user, $notrigger=0) { global $conf, $langs; @@ -547,6 +548,7 @@ class Expedition extends CommonObject { $numref = "EXP".$this->id; } + $this->newref = $numref; $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) { - $this->oldref=''; + $this->oldref = $this->ref; // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) @@ -636,11 +646,17 @@ class Expedition extends CommonObject if (@rename($dirsource, $dirdest)) { - $this->oldref = $oldref; - - dol_syslog("Rename ok"); - // Suppression ancien fichier PDF dans nouveau rep - dol_delete_file($dirdest.'/'.$oldref.'*.*'); + dol_syslog("Rename ok"); + // Rename docs starting with $oldref with $newref + $listoffiles=dol_dir_list($conf->expedition->dir_output.'/sending/'.$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); + } } } } @@ -653,14 +669,6 @@ class Expedition extends CommonObject $this->statut = 1; } - if (! $error) - { - // Call trigger - $result=$this->call_trigger('SHIPPING_VALIDATE',$user); - if ($result < 0) { $error++; } - // End call triggers - } - if (! $error) { $this->db->commit(); diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 783024df800..bc12821530f 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -374,9 +374,10 @@ class Fichinter extends CommonObject * Validate a intervention * * @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; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -398,6 +399,7 @@ class Fichinter extends CommonObject { $num = $this->ref; } + $this->newref = $num; $sql = "UPDATE ".MAIN_DB_PREFIX."fichinter"; $sql.= " SET fk_statut = 1"; @@ -416,9 +418,17 @@ class Fichinter extends CommonObject $error++; } + if (! $error && ! $notrigger) + { + // Call trigger + $result=$this->call_trigger('FICHINTER_VALIDATE',$user); + if ($result < 0) { $error++; } + // End call triggers + } + if (! $error) { - $this->oldref = ''; + $this->oldref = $this->ref; // Rename directory if dir was a temporary 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) // to not lose the linked files $oldref = dol_sanitizeFileName($this->ref); - $snum = dol_sanitizeFileName($num); + $newref = dol_sanitizeFileName($num); $dirsource = $conf->ficheinter->dir_output.'/'.$oldref; - $dirdest = $conf->ficheinter->dir_output.'/'.$snum; + $dirdest = $conf->ficheinter->dir_output.'/'.$newref; 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)) { - $this->oldref = $oldref; - - dol_syslog("Rename ok"); - // Suppression ancien fichier PDF dans nouveau rep - dol_delete_file($conf->ficheinter->dir_output.'/'.$snum.'/'.$oldref.'*.*'); + dol_syslog("Rename ok"); + // Rename docs starting with $oldref with $newref + $listoffiles=dol_dir_list($conf->ficheinter->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); + } } } } @@ -454,14 +470,6 @@ class Fichinter extends CommonObject $this->date_validation=$now; } - if (! $error) - { - // Call trigger - $result=$this->call_trigger('FICHINTER_VALIDATE',$user); - if ($result < 0) { $error++; } - // End call triggers - } - if (! $error) { $this->db->commit(); diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 7983060490d..d5f4f400d5a 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -317,9 +317,10 @@ class CommandeFournisseur extends CommonOrder * * @param User $user Validator User * @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 */ - function valid($user,$idwarehouse=0) + function valid($user,$idwarehouse=0,$notrigger=0) { global $langs,$conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -342,12 +343,13 @@ class CommandeFournisseur extends CommonOrder $num = $this->getNextNumRef($soc); } else - { + { $num = $this->ref; } + $this->newref = $num; $sql = 'UPDATE '.MAIN_DB_PREFIX."commande_fournisseur"; - $sql.= " SET ref='".$num."',"; + $sql.= " SET ref='".$this->db->escape($num)."',"; $sql.= " fk_statut = 1,"; $sql.= " date_valid='".$this->db->idate(dol_now())."',"; $sql.= " fk_user_valid = ".$user->id; @@ -361,9 +363,17 @@ class CommandeFournisseur extends CommonOrder $error++; } + if (! $error && ! $notrigger) + { + // Call trigger + $result=$this->call_trigger('ORDER_SUPPLIER_VALIDATE',$user); + if ($result < 0) $error++; + // End call triggers + } + if (! $error) { - $this->oldref=''; + $this->oldref = $this->ref; // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) @@ -380,11 +390,17 @@ class CommandeFournisseur extends CommonOrder if (@rename($dirsource, $dirdest)) { - $this->oldref = $oldref; - dol_syslog("Rename ok"); - // Suppression ancien fichier PDF dans nouveau rep - dol_delete_file($dirdest.'/'.$oldref.'*.*'); + // Rename docs starting with $oldref with $newref + $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; } - 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) { $this->db->commit(); @@ -619,9 +623,10 @@ class CommandeFournisseur extends CommonOrder $num = $this->getNextNumRef($soc); } else - { + { $num = $this->ref; } + $this->newref = $num; $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; $sql.= " SET ref='".$this->db->escape($num)."',"; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 9c72319f74f..988ee0b6a96 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -257,7 +257,7 @@ class FactureFournisseur extends CommonInvoice { // Call trigger $result=$this->call_trigger('BILL_SUPPLIER_CREATE',$user); - if ($result < 0) $error++; + if ($result < 0) $error++; // End call triggers if (! $error) @@ -413,7 +413,7 @@ class FactureFournisseur extends CommonInvoice $this->socid = $obj->socid; $this->socnom = $obj->socnom; - + // Retreive all extrafield // fetch optionals attributes and labels require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); @@ -611,7 +611,7 @@ class FactureFournisseur extends CommonInvoice { // Call trigger $result=$this->call_trigger('BILL_SUPPLIER_UPDATE',$user); - if ($result < 0) $error++; + if ($result < 0) $error++; // End call triggers } } @@ -682,9 +682,9 @@ class FactureFournisseur extends CommonInvoice // Call trigger $result=$this->call_trigger('BILL_SUPPLIER_DELETE',$user); if ($result < 0) - { + { $this->db->rollback(); - return -1; + return -1; } // Fin appel triggers } @@ -776,7 +776,7 @@ class FactureFournisseur extends CommonInvoice { // Call trigger $result=$this->call_trigger('BILL_SUPPLIER_PAYED',$user); - if ($result < 0) $error++; + if ($result < 0) $error++; // End call triggers } else @@ -824,7 +824,7 @@ class FactureFournisseur extends CommonInvoice { // Call trigger $result=$this->call_trigger('BILL_SUPPLIER_UNPAYED',$user); - if ($result < 0) $error++; + if ($result < 0) $error++; // End call triggers } else @@ -852,9 +852,10 @@ class FactureFournisseur extends CommonInvoice * @param User $user Object user that validate * @param string $force_number Reference to force on invoice * @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 */ - function validate($user, $force_number='', $idwarehouse=0) + function validate($user, $force_number='', $idwarehouse=0, $notrigger=0) { global $conf,$langs; @@ -886,9 +887,10 @@ class FactureFournisseur extends CommonInvoice $num = $this->getNextNumRef($this->client); } else - { + { $num = $this->ref; } + $this->newref = $num; $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn"; $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) { - $this->oldref = ''; + $this->oldref = $this->ref; // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { // On renomme repertoire facture ($this->ref = ancienne ref, $num = nouvelle ref) // in order not to lose the attached files - $facref = dol_sanitizeFileName($this->ref); - $snumfa = dol_sanitizeFileName($num); + $oldref = dol_sanitizeFileName($this->ref); + $newref = dol_sanitizeFileName($num); - $dirsource = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2).$facref; - $dirdest = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2).$snumfa; + $dirsource = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2).$oldref; + $dirdest = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2).$newref; if (file_exists($dirsource)) { dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); if (@rename($dirsource, $dirdest)) { - $this->oldref = $facref; - dol_syslog("Rename ok"); - // Suppression ancien fichier PDF dans nouveau rep - dol_delete_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id,2).$snumfa.'/'.$facref.'*.*'); + // Rename docs starting with $oldref with $newref + $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 } - // Triggers call - if (! $error) - { - // Call trigger - $result=$this->call_trigger('BILL_SUPPLIER_VALIDATE',$user); - if ($result < 0) $error++; - // End call triggers - } - if (! $error) { $this->db->commit(); @@ -1128,8 +1136,8 @@ class FactureFournisseur extends CommonInvoice global $conf, $langs, $user; // Call trigger $result=$this->call_trigger('LINEBILL_SUPPLIER_CREATE',$user); - if ($result < 0) - { + if ($result < 0) + { $this->db->rollback(); return -1; } @@ -1224,7 +1232,7 @@ class FactureFournisseur extends CommonInvoice } $this->db->begin(); - + $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn_det SET"; $sql.= " description ='".$this->db->escape($desc)."'"; $sql.= ", pu_ht = ".price2num($pu_ht); @@ -1258,8 +1266,8 @@ class FactureFournisseur extends CommonInvoice global $conf, $langs, $user; // Call trigger $result=$this->call_trigger('LINEBILL_SUPPLIER_UPDATE',$user); - if ($result < 0) - { + if ($result < 0) + { $this->db->rollback(); return -1; } @@ -1270,7 +1278,7 @@ class FactureFournisseur extends CommonInvoice $result=$this->update_price('','auto'); $this->db->commit(); - + return $result; } else @@ -1303,7 +1311,7 @@ class FactureFournisseur extends CommonInvoice { // Call trigger $result=$this->call_trigger('LINEBILL_SUPPLIER_DELETE',$user); - if ($result < 0) $error++; + if ($result < 0) $error++; // End call triggers } diff --git a/htdocs/livraison/class/livraison.class.php b/htdocs/livraison/class/livraison.class.php index ebe46c78ac3..e95fac9f639 100644 --- a/htdocs/livraison/class/livraison.class.php +++ b/htdocs/livraison/class/livraison.class.php @@ -359,18 +359,21 @@ class Livraison extends CommonObject $soc = new Societe($this->db); $soc->fetch($this->socid); - // on verifie si le bon de livraison est en numerotation provisoire - $livref = substr($this->ref, 1, 4); - if ($livref == 'PROV') + if (preg_match('/^[\(]?PROV/i', $this->ref)) + { + $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 // de decrementer 2 fois le stock. $sql = "SELECT ref"; $sql.= " FROM ".MAIN_DB_PREFIX."livraison"; - $sql.= " WHERE ref = '".$numref."'"; + $sql.= " WHERE ref = '".$this->db->escape($numref)."'"; $sql.= " AND fk_statut <> 0"; $sql.= " AND entity = ".$conf->entity; @@ -393,10 +396,24 @@ class Livraison extends CommonObject $sql.= " AND fk_statut = 0"; $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 if (preg_match('/^[\(]?PROV/i', $this->ref)) @@ -413,11 +430,17 @@ class Livraison extends CommonObject if (@rename($dirsource, $dirdest)) { - $this->oldref = $oldref; - - dol_syslog("Rename ok"); - // Suppression ancien fichier PDF dans nouveau rep - dol_delete_file($dirdest.'/'.$oldref.'*.*'); + dol_syslog("Rename ok"); + // Rename docs starting with $oldref with $newref + $listoffiles=dol_dir_list($conf->expedition->dir_output.'/receipt/'.$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); + } } } } @@ -431,12 +454,17 @@ class Livraison extends CommonObject dol_syslog(get_class($this)."::valid ok"); } - else + + if (! $error) + { + $this->db->commit(); + return 1; + } + else { - $this->db->rollback(); - $this->error=$this->db->error()." - sql=$sql"; - return -1; - } + $this->db->rollback(); + return -1; + } } } } @@ -446,21 +474,6 @@ class Livraison extends CommonObject dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR); 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; - } } /**