From e3e00b034b13a11edf4ff64bd3ae528b03d1d523 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 25 May 2013 20:43:01 +0200 Subject: [PATCH] Fix: Dir with linked files was not renamed when invoices was renamed with its final ref (linked files were lost) Fix: Ref visible into message was wrong. Fix: Bad counting of product/service available --- .../fourn/class/fournisseur.facture.class.php | 41 ++++++++++++++++++- htdocs/fourn/facture/fiche.php | 12 +++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 31a8fc85b77..e3bc1fadb8b 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -659,7 +659,7 @@ class FactureFournisseur extends CommonInvoice } } } - + // Remove extrafields if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used { @@ -855,6 +855,45 @@ class FactureFournisseur extends CommonInvoice } } + if (! $error) + { + $this->oldref = ''; + + // 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) + // afin de ne pas perdre les fichiers attaches + $facref = dol_sanitizeFileName($this->ref); + $snumfa = 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; + 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.'*.*'); + } + } + } + } + + // Set new ref and define current statut + if (! $error) + { + $this->ref = $num; + $this->statut=1; + //$this->date_validation=$now; this is stored into log table + } + + // Triggers call if (! $error) { // Appel des triggers diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 3a157d74ceb..8774c2b871c 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -114,8 +114,18 @@ elseif ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->fourni $object->fetch($id); $object->fetch_thirdparty(); + $qualified_for_stock_change=0; + if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) + { + $qualified_for_stock_change=$object->hasProductsOrServices(2); + } + else + { + $qualified_for_stock_change=$object->hasProductsOrServices(1); + } + // Check parameters - if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $object->hasProductsOrServices(1)) + if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) { $langs->load("stocks"); if (! $idwarehouse || $idwarehouse == -1)