From fc5f4007a12e3e1cffb93f928d9d2bc02dbd9aef Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Fri, 5 May 2017 16:54:05 +0200
Subject: [PATCH] Debug accountancy module. Page for bank journalization is
 still KO.

---
 htdocs/accountancy/admin/journals_list.php    |  5 +++-
 htdocs/core/menus/standard/eldy.lib.php       | 29 +++++++++++++------
 .../install/mysql/migration/5.0.0-6.0.0.sql   |  2 ++
 .../mysql/tables/llx_accounting_journal.sql   |  1 +
 4 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/htdocs/accountancy/admin/journals_list.php b/htdocs/accountancy/admin/journals_list.php
index 065d750ca82..0b13bfc7d4d 100644
--- a/htdocs/accountancy/admin/journals_list.php
+++ b/htdocs/accountancy/admin/journals_list.php
@@ -61,6 +61,8 @@ if ($page == -1) { $page = 0 ; }
 $offset = $listlimit * $page ;
 $pageprev = $page - 1;
 $pagenext = $page + 1;
+if (empty($sortfield)) $sortfield='code';
+if (empty($sortorder)) $sortorder='ASC';
 
 $error = 0;
 
@@ -125,7 +127,8 @@ complete_dictionary_with_modules($taborder,$tabname,$tablib,$tabsql,$tabsqlsort,
 
 // Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
 $elementList = array();
-	$sourceList = array(
+    // Must match ids defined into eldy.lib.php 
+    $sourceList = array(
 			'1' => $langs->trans('AccountingJournalType1'),
 			'2' => $langs->trans('AccountingJournalType2'),
 			'3' => $langs->trans('AccountingJournalType3'),
diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php
index aa905b4ef93..4c873830948 100644
--- a/htdocs/core/menus/standard/eldy.lib.php
+++ b/htdocs/core/menus/standard/eldy.lib.php
@@ -1007,8 +1007,8 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
 					// Multi journal
 					$sql = "SELECT rowid, code, label, nature";
 					$sql.= " FROM ".MAIN_DB_PREFIX."accounting_journal";
-					// $sql.= " WHERE entity = ".$conf->entity;
-					$sql.= " ORDER BY code";
+					$sql.= " WHERE entity = ".$conf->entity;
+					$sql.= " ORDER BY nature";
 
 					$resql = $db->query($sql);
 					if ($resql)
@@ -1021,14 +1021,25 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu
     						while ($i < $numr)
     						{
     							$objp = $db->fetch_object($resql);
-    
-    							if ($objp->nature == 1) $nature="sells";
-    							if ($objp->nature == 2) $nature="purchases";
-    							if ($objp->nature == 3) $nature="bank";
-    							if ($objp->nature == 4) $nature="various";
+
+    							$nature='';
+    							// Must match array $sourceList defined into journals_list.php 
+    							if ($objp->nature == 2) $nature="sells";
+    							if ($objp->nature == 3) $nature="purchases";
+    							if ($objp->nature == 4) $nature="bank";
+    							if ($objp->nature == 1) $nature="various";
     							if ($objp->nature == 9) $nature="hasnew";
-    
-    							if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy/',$leftmenu)) $newmenu->add('/accountancy/journal/'.$nature.'journal.php?mainmenu=accountancy&leftmenu=accountancy_journal&code_journal='.$objp->code,dol_trunc($objp->label,25),2,$user->rights->accounting->comptarapport->lire);
+    							
+    							// To enable when page exists
+    							if (empty($conf->global->MAIN_FEATURES_LEVEL))
+    							{
+    							    if ($nature == 'various' || $nature == 'hasnew') $nature='';	
+    							}
+    								
+    							if ($nature)
+    							{
+                                    if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy/',$leftmenu)) $newmenu->add('/accountancy/journal/'.$nature.'journal.php?mainmenu=accountancy&leftmenu=accountancy_journal&code_journal='.$objp->code,dol_trunc($objp->label,25),2,$user->rights->accounting->comptarapport->lire);
+    							}
     							$i++;
     						}
 						}
diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql
index f88ffd05687..d96210dcbfe 100644
--- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql
+++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql
@@ -120,6 +120,8 @@ INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (
 INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (4,'OD', 'Journal des opérations diverses', 0, 1);
 INSERT INTO llx_accounting_journal (rowid, code, label, nature, active) VALUES (5,'AN', 'Journal des à-nouveaux', 9, 1);
 
+ALTER TABLE llx_accounting_journal ADD COLUMN entity integer DEFAULT 1;
+
 ALTER TABLE llx_paiementfourn ADD COLUMN model_pdf varchar(255);
 
 
diff --git a/htdocs/install/mysql/tables/llx_accounting_journal.sql b/htdocs/install/mysql/tables/llx_accounting_journal.sql
index bccfb234c3e..a435de3cd80 100644
--- a/htdocs/install/mysql/tables/llx_accounting_journal.sql
+++ b/htdocs/install/mysql/tables/llx_accounting_journal.sql
@@ -20,6 +20,7 @@
 create table llx_accounting_journal
 (
   rowid             integer AUTO_INCREMENT PRIMARY KEY,
+  entity            integer DEFAULT 1,
   code       		varchar(32) NOT NULL,
   label             varchar(128) NOT NULL,
   nature			smallint DEFAULT 0 NOT NULL,			-- type of journals (1:various operations / 2:sale / 3:purchase / 4:bank / 9: has-new)
-- 
GitLab