From 2901b18fa673df9f9a725d09e5e81673a8c23112 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Mon, 29 Jun 2009 18:33:05 +0000
Subject: [PATCH] Fix: Cheque receipts was not stored in correct directory

---
 htdocs/compta/paiement/cheque/fiche.php                  | 6 ++++--
 htdocs/compta/paiement/rapport.php                       | 2 +-
 htdocs/document.php                                      | 4 ++--
 htdocs/includes/modules/cheque/pdf/pdf_blochet.class.php | 4 ++--
 htdocs/lib/functions.lib.php                             | 6 ++++--
 5 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/htdocs/compta/paiement/cheque/fiche.php b/htdocs/compta/paiement/cheque/fiche.php
index 03bbb1ff511..9fee3f401f1 100644
--- a/htdocs/compta/paiement/cheque/fiche.php
+++ b/htdocs/compta/paiement/cheque/fiche.php
@@ -55,6 +55,8 @@ if ($page < 0) { $page = 0 ; }
 $limit = $conf->liste_limit;
 $offset = $limit * $page ;
 
+$dir=$conf->banque->dir_output.'/bordereau/';
+
 
 /*
  * Actions
@@ -454,9 +456,9 @@ if ($_GET['action'] != 'new')
 {
 	if ($remisecheque->statut == 1)
 	{
-		$dir = $conf->comptabilite->dir_output.'/bordereau/'.get_exdir($remisecheque->number);
+		$dirchequereceipts = $dir.get_exdir($remisecheque->number,2,1).'/'.$remisecheque->ref;
 		$gen = array('blochet'=>'blochet');
-		$formfile->show_documents("remisecheque","",$dir,$_SERVER["PHP_SELF"].'?id='.$remisecheque->id,$gen,1);
+		$formfile->show_documents("remisecheque","",$dirchequereceipts,$_SERVER["PHP_SELF"].'?id='.$remisecheque->id,$gen,1);
 	}
 }
 
diff --git a/htdocs/compta/paiement/rapport.php b/htdocs/compta/paiement/rapport.php
index 112bcbbd6ee..849ed02273b 100644
--- a/htdocs/compta/paiement/rapport.php
+++ b/htdocs/compta/paiement/rapport.php
@@ -38,7 +38,7 @@ if ($user->societe_id > 0)
 {
 	$action = '';
 	$socid = $user->societe_id;
-	$dir = DOL_DATA_ROOT.'/private/'.$user->id.'/compta';
+	$dir = $conf->facture->dir_output.'/payments/private/'.$user->id;
 }
 
 $year = $_GET["year"];
diff --git a/htdocs/document.php b/htdocs/document.php
index d2babbac6a9..58486bf9569 100644
--- a/htdocs/document.php
+++ b/htdocs/document.php
@@ -212,8 +212,8 @@ if ($modulepart)
 		{
 			$accessallowed=1;
 		}
-		if ($user->societe_id > 0) $original_file=DOL_DATA_ROOT.'/private/'.$user->id.'/compta/'.$original_file;
-		else $original_file=$conf->compta->dir_output.'/payments/'.$original_file;
+		if ($user->societe_id > 0) $original_file=$conf->facture->dir_output.'/payments/private/'.$user->id.'/'.$original_file;
+		else $original_file=$conf->facture->dir_output.'/payments/'.$original_file;
 		//$sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."fichinter WHERE ref='$refname'";
 	}
 
diff --git a/htdocs/includes/modules/cheque/pdf/pdf_blochet.class.php b/htdocs/includes/modules/cheque/pdf/pdf_blochet.class.php
index b0fcd79e38c..737b0fa6b97 100644
--- a/htdocs/includes/modules/cheque/pdf/pdf_blochet.class.php
+++ b/htdocs/includes/modules/cheque/pdf/pdf_blochet.class.php
@@ -95,7 +95,7 @@ class BordereauChequeBlochet extends FPDF
 		$outputlangs->load("bills");
 		$outputlangs->load("products");
 
-		$dir = $_dir . "/".get_exdir($number);
+		$dir = $_dir . "/".get_exdir($number,2,1)."/".$number;
 
 		if (! is_dir($dir))
 		{
@@ -110,7 +110,7 @@ class BordereauChequeBlochet extends FPDF
 
 		$month = sprintf("%02d",$month);
 		$year = sprintf("%04d",$year);
-		$_file = $dir . "bordereau-00".$number.".pdf"; //Todo: r�paration provisoire, ajout de 2 zero
+		$_file = $dir . "/bordereau-".$number.".pdf";
 
 		// Protection et encryption du pdf
 		if ($conf->global->PDF_SECURITY_ENCRYPTION)
diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php
index 7af1993798c..4ce047ebc64 100644
--- a/htdocs/lib/functions.lib.php
+++ b/htdocs/lib/functions.lib.php
@@ -2376,11 +2376,13 @@ function yn($yesno, $case=1, $color=0)
  *	\remarks    Examples: 1->"0/0/1/", 15->"0/1/5/"
  *	\param      $num        Id to develop
  *	\param      $level		Level of development (1, 2 or 3 level)
+ * 	\param		$alpha		Use alpha ref
  */
-function get_exdir($num,$level=3)
+function get_exdir($num,$level=3,$alpha=0)
 {
 	$path = '';
-	$num = eregi_replace('[^0-9]','',$num);
+	if (empty($alpha)) $num = eregi_replace('[^0-9]','',$num);
+	else $num = eregi_replace('^.*\-','',$num);
 	$num = substr("000".$num, -$level);
 	if ($level == 1) $path = substr($num,0,1).'/';
 	if ($level == 2) $path = substr($num,1,1).'/'.substr($num,0,1).'/';
-- 
GitLab