From 14a078c9a7b32f13cca4d33c80aae25df2892d7b Mon Sep 17 00:00:00 2001
From: aspangaro <alexandre.spangaro@gmail.com>
Date: Tue, 3 Feb 2015 06:39:44 +0100
Subject: [PATCH] FIXED Accountancy clean code

---
 htdocs/accountancy/admin/export.php           | 35 +++++++------
 htdocs/accountancy/bookkeeping/list.php       |  4 +-
 htdocs/accountancy/journal/bankjournal.php    | 44 ++++++++--------
 htdocs/accountancy/journal/cashjournal.php    | 50 +++++++++---------
 .../accountancy/journal/purchasesjournal.php  | 36 ++++++-------
 htdocs/accountancy/journal/sellsjournal.php   | 52 ++++++++++---------
 htdocs/core/modules/modAccounting.class.php   |  2 +-
 htdocs/langs/en_US/accountancy.lang           |  4 +-
 8 files changed, 119 insertions(+), 108 deletions(-)

diff --git a/htdocs/accountancy/admin/export.php b/htdocs/accountancy/admin/export.php
index 8fd0795c262..2954047e310 100644
--- a/htdocs/accountancy/admin/export.php
+++ b/htdocs/accountancy/admin/export.php
@@ -42,7 +42,7 @@ if (!$user->admin)
 
 $action = GETPOST('action', 'alpha');
 
-// Other parameters ACCOUNTING_*
+// Other parameters ACCOUNTING_EXPORT_*
 $list = array (
 		'ACCOUNTING_EXPORT_SEPARATORCSV',
 		'ACCOUNTING_EXPORT_DATE',
@@ -114,20 +114,24 @@ print '</tr>';
 $var = ! $var;
 
 print '<tr ' . $bc[$var] . '>';
-print "<td>" . $langs->trans("Selectmodelcsv") . "</td>";
-print "<td>";
-print '<select class="flat" name="modelcsv" id="modelcsv">';
-print '<option value="0"';
-if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 0) {
-	print ' selected="selected"';
+print '<td width="50%">' . $langs->trans("Selectmodelcsv") . '</td>';
+if (! $conf->use_javascript_ajax)
+{
+	print '<td class="nowrap">';
+	print $langs->trans("NotAvailableWhenAjaxDisabled");
+	print "</td>";
 }
-print '>' . $langs->trans("Modelcsv_normal") . '</option>';
-print '<option value="1"';
-if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) {
-	print ' selected="selected"';
+else
+{
+	print '<td>';
+	$listmodelcsv=array(
+		'1'=>$langs->trans("Modelcsv_normal"),
+		'2'=>$langs->trans("Modelcsv_CEGID")
+	);
+	print $form->selectarray("modelcsv",$listmodelcsv,$conf->global->ACCOUNTING_EXPORT_MODELCSV,0);
+
+	print '</td>';
 }
-print '>' . $langs->trans("Modelcsv_CEGID") . '</option>';
-print "</select>";
 print "</td></tr>";
 print "</table>";
 
@@ -143,6 +147,7 @@ if ($num) {
 	print '<tr class="liste_titre">';
 	print '<td colspan="3">' . $langs->trans('OtherOptions') . '</td>';
 	print "</tr>\n";
+	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV > 1) print '<tr><td colspan="2" bgcolor="red"><b>' . $langs->trans('OptionsDeactivatedForThisExportModel') . '</b></td></tr>';
 }
 
 foreach ( $list as $key ) {
@@ -152,7 +157,7 @@ foreach ( $list as $key ) {
 
 	// Param
 	$label = $langs->trans($key);
-	print '<td>' . $label . '</td>';
+	print '<td width="50%">' . $label . '</td>';
 
 	// Value
 	print '<td>';
@@ -163,7 +168,7 @@ foreach ( $list as $key ) {
 print '</form>';
 print "</table>\n";
 
-print '<br /><div style="text-align:center"><input type="submit" class="button" value="' . $langs->trans('Modify') . '" name="button"></div>';
+print '<br /><div align="center"><input type="submit" class="button" value="' . $langs->trans('Modify') . '" name="button"></div>';
 
 llxFooter();
 $db->close();
\ No newline at end of file
diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php
index f1dc892c10f..6c06c2ba3d7 100644
--- a/htdocs/accountancy/bookkeeping/list.php
+++ b/htdocs/accountancy/bookkeeping/list.php
@@ -75,7 +75,7 @@ if ($action == 'delbookkeeping') {
 			setEventMessage($object->errors, 'errors');
 		}
 	}
-} // export csv
+} // Export
 else if ($action == 'export_csv') {
 	
 	header('Content-Type: text/csv');
@@ -160,7 +160,7 @@ else {
 		print '<form name="add" action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
 		print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
 		print '<input type="hidden" name="action" value="export_csv">';
-		print '<input type="submit" class="button" style="float: right;" value="Export CSV" />';
+		print '<input type="submit" class="button" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />';
 		print '</form>';
 		
 		print '<table class="noborder" width="100%">';
diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php
index 95a00eaf950..5fc98690933 100644
--- a/htdocs/accountancy/journal/bankjournal.php
+++ b/htdocs/accountancy/journal/bankjournal.php
@@ -4,7 +4,7 @@
  * Copyright (C) 2011		Juanjo Menent		<jmenent@2byte.es>
  * Copyright (C) 2012		Regis Houssin		<regis@dolibarr.fr>
  * Copyright (C) 2013		Christophe Battarel	<christophe.battarel@altairis.fr>
- * Copyright (C) 2013-2014  Alexandre Spangaro	<alexandre.spangaro@gmail.com>
+ * Copyright (C) 2013-2015  Alexandre Spangaro	<alexandre.spangaro@gmail.com>
  * Copyright (C) 2013-2014  Florian Henry		<florian.henry@open-concept.pro>
  * Copyright (C) 2013-2014  Olivier Geffroy		<jeff@jeffinfo.com>
  *
@@ -99,10 +99,10 @@ $idpays = $p[0];
 
 $sql = "SELECT b.rowid , b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type, soc.code_compta, ba.courant,";
 $sql .= " soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, ba.account_number, bu1.type as typeop";
-$sql .= " FROM " . MAIN_DB_PREFIX . "bank b";
-$sql .= " JOIN " . MAIN_DB_PREFIX . "bank_account ba on b.fk_account=ba.rowid";
-$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
-$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe soc on bu1.url_id=soc.rowid";
+$sql .= " FROM " . MAIN_DB_PREFIX . "bank as b";
+$sql .= " JOIN " . MAIN_DB_PREFIX . "bank_account as ba on b.fk_account=ba.rowid";
+$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
+$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc on bu1.url_id=soc.rowid";
 // To isolate the cash of the other accounts
 $sql .= " WHERE ba.courant <> 2";
 $sql .= " AND ba.rowid=".$id_accountancy_journal;
@@ -169,10 +169,12 @@ if ($result) {
 		}
 		$links = $object->get_url($obj->rowid);
 
+
 		foreach ( $links as $key => $val )
 		{
 			$tabtype[$obj->rowid] = $links[$key]['type'];
 
+
 			if ($links[$key]['type'] == 'payment')
 			{
 				$paymentstatic->id = $links[$key]['url_id'];
@@ -401,18 +403,21 @@ if ($action == 'writeBookKeeping')
 		setEventMessage($langs->trans('Success'), 'mesgs');
 	}
 }
-// export csv
+// Export
 if ($action == 'export_csv')
 {
 	$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
+	$bank_journal = $conf->global->ACCOUNTING_BANK_JOURNAL;
 
 	header('Content-Type: text/csv');
 	header('Content-Disposition: attachment;filename=journal_banque.csv');
 
 	$companystatic = new Client($db);
 
-	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) 	// Modèle Export Cegid Expert
+	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) 	// Model Cegid Expert Export
 	{
+		$sep = ";";
+		
 		foreach ( $tabpay as $key => $val ) {
 			$date = dol_print_date($db->jdate($val["date"]), '%d%m%Y');
 
@@ -420,23 +425,23 @@ if ($action == 'export_csv')
 			$companystatic->name = $tabcompany[$key]['name'];
 
 			// Bank
-			print $date . $sep;
-			print $conf->global->ACCOUNTING_BANK_JOURNAL . $sep;
 			foreach ( $tabbq[$key] as $k => $mt ) {
+				print $date . $sep;
+				print $bank_journal . $sep;
 				print length_accountg(html_entity_decode($k)) . $sep;
 				print $sep;
 				print ($mt < 0 ? 'C' : 'D') . $sep;
 				print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
 				print $val["type_payment"] . $sep;
-				print $sep;
+				print $val["ref"] . $sep;
+				print "\n";
 			}
-			print "\n";
 
 			// Third party
 			foreach ( $tabtp[$key] as $k => $mt ) {
 				if ($mt) {
 					print $date . $sep;
-					print $conf->global->ACCOUNTING_BANK_JOURNAL . $sep;
+					print $bank_journal . $sep;
 					if ($val["lib"] == '(SupplierInvoicePayment)') {
 						print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) . $sep;
 					} else {
@@ -446,12 +451,12 @@ if ($action == 'export_csv')
 					print ($mt < 0 ? 'D' : 'C') . $sep;
 					print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
 					print $val["type_payment"] . $sep;
-					print $sep;
+					print $val["ref"] . $sep;
 					print "\n";
 				}
 			}
 		}
-	} else 	// Modèle Export Classique
+	} else 	// Model Classic Export
 	{
 		foreach ( $tabpay as $key => $val ) {
 			$date = dol_print_date($db->jdate($val["date"]), 'day');
@@ -459,24 +464,22 @@ if ($action == 'export_csv')
 			$companystatic->id = $tabcompany[$key]['id'];
 			$companystatic->name = $tabcompany[$key]['name'];
 
-			print '"' . $date . '"' . $sep;
-			print '"' . $val["type_payment"] . '"' . $sep;
-
 			// Bank
 			foreach ( $tabbq[$key] as $k => $mt ) {
+				print '"' . $date . '"' . $sep;
+				print '"' . $val["type_payment"] . '"' . $sep;
 				print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
 				print '"' . $langs->trans("Bank") . '"' . $sep;
 				print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
 				print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
+				print "\n";
 			}
-			print "\n";
 
 			// Third party
 			foreach ( $tabtp[$key] as $k => $mt ) {
 				if ($mt) {
 					print '"' . $date . '"' . $sep;
 					print '"' . $val["type_payment"] . '"' . $sep;
-
 					print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
 					print '"' . $companystatic->name . '"' . $sep;
 					print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
@@ -503,7 +506,7 @@ else
 	$period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1);
 	report_header($namereport, $namelink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''));
 
-	print '<input type="button" class="button" style="float: right;" value="Export CSV" onclick="launch_export();" />';
+	print '<input type="button" class="button" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />';
 
 	print '<input type="button" class="button" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writeBookKeeping();" />';
 
@@ -586,5 +589,4 @@ else
 	// End of page
 	llxFooter();
 }
-
 $db->close();
diff --git a/htdocs/accountancy/journal/cashjournal.php b/htdocs/accountancy/journal/cashjournal.php
index 51b8625f9b3..bbd74a8c29c 100644
--- a/htdocs/accountancy/journal/cashjournal.php
+++ b/htdocs/accountancy/journal/cashjournal.php
@@ -4,7 +4,7 @@
  * Copyright (C) 2011		Juanjo Menent		<jmenent@2byte.es>
  * Copyright (C) 2012		Regis Houssin		<regis@dolibarr.fr>
  * Copyright (C) 2013		Christophe Battarel	<christophe.battarel@altairis.fr>
- * Copyright (C) 2013-2014  Alexandre Spangaro	<alexandre.spangaro@gmail.com>
+ * Copyright (C) 2013-2015  Alexandre Spangaro	<alexandre.spangaro@gmail.com>
  * Copyright (C) 2013-2014  Florian Henry	    <florian.henry@open-concept.pro>
  * Copyright (C) 2013-2014  Olivier Geffroy     <jeff@jeffinfo.com>
  *
@@ -91,10 +91,10 @@ $idpays = $p[0];
 
 $sql = "SELECT b.rowid , b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type, soc.code_compta, ba.courant,";
 $sql .= " soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, ba.account_number, bu1.type as typeop";
-$sql .= " FROM " . MAIN_DB_PREFIX . "bank b";
-$sql .= " JOIN " . MAIN_DB_PREFIX . "bank_account ba on b.fk_account=ba.rowid";
-$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
-$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe soc on bu1.url_id=soc.rowid";
+$sql .= " FROM " . MAIN_DB_PREFIX . "bank as b";
+$sql .= " JOIN " . MAIN_DB_PREFIX . "bank_account as ba on b.fk_account=ba.rowid";
+$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'";
+$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc on bu1.url_id=soc.rowid";
 
 // Code opération type caisse
 $sql .= " WHERE ba.courant = 2";
@@ -365,67 +365,69 @@ if ($action == 'writeBookKeeping') {
 		setEventMessage($langs->trans('Success'), 'mesgs');
 	}
 }
-// export csv
+// Export
 if ($action == 'export_csv') {
 	$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
+	$cash_journal = $conf->global->ACCOUNTING_CASH_JOURNAL;
 
 	header('Content-Type: text/csv');
 	header('Content-Disposition:attachment;filename=journal_caisse.csv');
 
-	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) 	// Modèle Export Cegid Expert
+	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) 	// Model Cegid Expert Export
 	{
+		$sep = ";";
+
 		foreach ( $tabpay as $key => $val ) {
 			$date = dol_print_date($db->jdate($val["date"]), '%d%m%Y');
 
 			// Cash
-			print $date . $sep;
-			print $conf->global->ACCOUNTING_CASH_JOURNAL . $sep;
-
 			foreach ( $tabbq[$key] as $k => $mt ) {
+				print $date . $sep;
+				print $cash_journal . $sep;
 				print length_accountg(html_entity_decode($k)) . $sep;
 				print $sep;
 				print ($mt < 0 ? 'C' : 'D') . $sep;
-				print price($mt) . $sep;
+				print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
+				print $val["type_payment"] . $sep;
+				print $val["ref"] . $sep;
+				print "\n";
 			}
-			print utf8_decode($langs->trans("CashPayment")) . $sep;
-			print $val["ref"] . $sep;
-			print "\n";
 
 			// Third party
 			foreach ( $tabtp[$key] as $k => $mt ) {
 				if ($mt) {
 					print $date . $sep;
-					print $conf->global->ACCOUNTING_CASH_JOURNAL . $sep;
-					if ($obj->label == '(SupplierInvoicePayment)') {
+					print $cash_journal . $sep;
+					if ($val["lib"] == '(SupplierInvoicePayment)') {
 						print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) . $sep;
 					} else {
 						print length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) . $sep;
 					}
 					print length_accounta(html_entity_decode($k)) . $sep;
 					print ($mt < 0 ? 'D' : 'C') . $sep;
-					print price($mt) . $sep;
-					print $langs->trans("ThirdParty") . $sep;
+					print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
+					print $val["type_payment"] . $sep;
 					print $val["ref"] . $sep;
 					print "\n";
 				}
 			}
 		}
-	} else 	// Modèle Export Classique
+	} else 	// Model Classic Export
 	{
 		foreach ( $tabpay as $key => $val ) {
 			$date = dol_print_date($db->jdate($val["date"]), 'day');
-			print '"' . $date . '"' . $sep;
-			print '"' . $val["ref"] . '"' . $sep;
 
 			// Cash
 			foreach ( $tabbq[$key] as $k => $mt ) {
+				print '"' . $date . '"' . $sep;
+				print '"' . $val["ref"] . '"' . $sep;
 				print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
 				print '"' . $langs->trans("Cash") . '"' . $sep;
 				print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
 				print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
+				print "\n";
 			}
-			print "\n";
-
+			
 			// Third party
 			foreach ( $tabtp[$key] as $k => $mt ) {
 				if ($mt) {
@@ -455,7 +457,7 @@ if ($action == 'export_csv') {
 	$period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1);
 	report_header($name, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''));
 
-	print '<input type="button" class="button" style="float: right;" value="Export CSV" onclick="launch_export();" />';
+	print '<input type="button" class="button" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />';
 
 	print '<input type="button" class="button" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writeBookKeeping();" />';
 
diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php
index 68bcdaa394f..8b9b7929db8 100644
--- a/htdocs/accountancy/journal/purchasesjournal.php
+++ b/htdocs/accountancy/journal/purchasesjournal.php
@@ -242,16 +242,19 @@ if ($action == 'writebookkeeping') {
 
 $companystatic = new Societe($db);
 
-// export csv
+// Export
 if ($action == 'export_csv')
 {
 	$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
+	$purchase_journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL;
 
 	header('Content-Type: text/csv');
 	header('Content-Disposition: attachment;filename=journal_achats.csv');
 
-	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) 	// Modèle Export Cegid Expert
+	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) 	// Model Cegid Expert Export
 	{
+		$sep = ";";
+		
 		foreach ( $tabfac as $key => $val ) {
 			$date = dol_print_date($db->jdate($val["date"]), '%d%m%Y');
 
@@ -263,7 +266,7 @@ if ($action == 'export_csv')
 
 				if ($mt) {
 					print $date . $sep;
-					print $conf->global->ACCOUNTING_PURCHASE_JOURNAL . $sep;
+					print $purchase_journal . $sep;
 					print length_accountg(html_entity_decode($k)) . $sep;
 					print $sep;
 					print ($mt < 0 ? 'C' : 'D') . $sep;
@@ -275,11 +278,10 @@ if ($action == 'export_csv')
 			}
 
 			// VAT
-			// var_dump($tabtva);
 			foreach ( $tabtva[$key] as $k => $mt ) {
 				if ($mt) {
 					print $date . $sep;
-					print $conf->global->ACCOUNTING_PURCHASE_JOURNAL . $sep;
+					print $purchase_journal . $sep;
 					print length_accountg(html_entity_decode($k)) . $sep;
 					print $sep;
 					print ($mt < 0 ? 'C' : 'D') . $sep;
@@ -289,20 +291,20 @@ if ($action == 'export_csv')
 					print "\n";
 				}
 			}
-			print $date . $sep;
-			print $conf->global->ACCOUNTING_PURCHASE_JOURNAL . $sep;
-			print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) . $sep;
 
 			foreach ( $tabttc[$key] as $k => $mt ) {
+				print $date . $sep;
+				print $purchase_journal . $sep;
+				print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) . $sep;
 				print length_accounta(html_entity_decode($k)) . $sep;
 				print ($mt < 0 ? 'D' : 'C') . $sep;
 				print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
 				print utf8_decode($companystatic->name) . $sep;
 				print $val["ref"];
+				print "\n";
 			}
-			print "\n";
 		}
-	} else 	// Modèle Export Classique
+	} else 	// Model Classic Export
 	{
 		foreach ( $tabfac as $key => $val ) {
 			$date = dol_print_date($db->jdate($val["date"]), 'day');
@@ -326,7 +328,6 @@ if ($action == 'export_csv')
 				}
 			}
 			// VAT
-			// var_dump($tabtva);
 			foreach ( $tabtva[$key] as $k => $mt ) {
 				if ($mt) {
 					print '"' . $date . '"' . $sep;
@@ -340,9 +341,9 @@ if ($action == 'export_csv')
 			}
 
 			// Third party
-			print '"' . $date . '"' . $sep;
-			print '"' . $val["ref"] . '"' . $sep;
 			foreach ( $tabttc[$key] as $k => $mt ) {
+				print '"' . $date . '"' . $sep;
+				print '"' . $val["ref"] . '"' . $sep;
 				print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
 				print '"' . utf8_decode($companystatic->name) . '"' . $sep;
 				print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
@@ -370,7 +371,7 @@ if ($action == 'export_csv')
 	$period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1);
 	report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''));
 
-	print '<input type="button" class="button" style="float: right;" value="Export CSV" onclick="launch_export();" />';
+	print '<input type="button" class="button" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />';
 
 	print '<input type="button" class="button" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />';
 
@@ -434,7 +435,6 @@ if ($action == 'export_csv')
 			}
 		}
 		// VAT
-		// var_dump($tabtva);
 		foreach ( $tabtva[$key] as $k => $mt ) {
 			if ($mt) {
 				print "<tr " . $bc[$var] . " >";
@@ -449,13 +449,11 @@ if ($action == 'export_csv')
 		print "<tr " . $bc[$var] . ">";
 
 		// Third party
-		print "<td>" . $date . "</td>";
-		print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
-
 		foreach ( $tabttc[$key] as $k => $mt ) {
+			print "<td>" . $date . "</td>";
+			print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
 			$companystatic->id = $tabcompany[$key]['id'];
 			$companystatic->name = $tabcompany[$key]['name'];
-
 			print "<td>" . length_accounta($k);
 			print "</td><td>" . $langs->trans("ThirdParty");
 			print ' (' . $companystatic->getNomUrl(0, 'supplier', 16) . ')';
diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php
index 892272d6a5a..4c260f9fa99 100644
--- a/htdocs/accountancy/journal/sellsjournal.php
+++ b/htdocs/accountancy/journal/sellsjournal.php
@@ -4,7 +4,7 @@
  * Copyright (C) 2011		Juanjo Menent			<jmenent@2byte.es>
  * Copyright (C) 2012		Regis Houssin			<regis@dolibarr.fr>
  * Copyright (C) 2013		Christophe Battarel		<christophe.battarel@altairis.fr>
- * Copyright (C) 2013-2014	Alexandre Spangaro		<alexandre.spangaro@gmail.com>
+ * Copyright (C) 2013-2015	Alexandre Spangaro		<alexandre.spangaro@gmail.com>
  * Copyright (C) 2013-2014	Florian Henry			<florian.henry@open-concept.pro>
  * Copyright (C) 2013-2014	Olivier Geffroy			<jeff@jeffinfo.com>
  *
@@ -93,7 +93,7 @@ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = fd.fk_produc
 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accountingaccount as aa ON aa.rowid = fd.fk_code_ventilation";
 $sql .= " JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture";
 $sql .= " JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc";
-$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva ct ON fd.tva_tx = ct.taux AND ct.fk_pays = '" . $idpays . "'";
+$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva as ct ON fd.tva_tx = ct.taux AND ct.fk_pays = '" . $idpays . "'";
 $sql .= " WHERE fd.fk_code_ventilation > 0 ";
 if (! empty($conf->multicompany->enabled)) {
 	$sql .= " AND f.entity = " . $conf->entity;
@@ -245,17 +245,20 @@ if ($action == 'writebookkeeping') {
 		}
 	}
 }
-// export csv
+// Export
 if ($action == 'export_csv') {
 	$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
+	$sell_journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
 
 	header('Content-Type: text/csv');
 	header('Content-Disposition: attachment;filename=journal_ventes.csv');
 
 	$companystatic = new Client($db);
 
-	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) 	// Modèle Export Cegid Expert
+	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) 	// Model Cegid Expert Export
 	{
+		$sep = ";";
+		
 		foreach ( $tabfac as $key => $val ) {
 			$companystatic->id = $tabcompany[$key]['id'];
 			$companystatic->name = $tabcompany[$key]['name'];
@@ -263,23 +266,23 @@ if ($action == 'export_csv') {
 
 			$date = dol_print_date($db->jdate($val["date"]), '%d%m%Y');
 
-			print $date . $sep;
-			print $conf->global->ACCOUNTING_SELL_JOURNAL . $sep;
-			print length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) . $sep;
 			foreach ( $tabttc[$key] as $k => $mt ) {
+				print $date . $sep;
+				print $sell_journal . $sep;
+				print length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) . $sep;
 				print length_accounta(html_entity_decode($k)) . $sep;
 				print ($mt < 0 ? 'C' : 'D') . $sep;
 				print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
 				print utf8_decode($companystatic->name) . $sep;
+				print $val["ref"];
+				print "\n";
 			}
-			print $val["ref"];
-			print "\n";
 
 			// Product / Service
 			foreach ( $tabht[$key] as $k => $mt ) {
 				if ($mt) {
 					print $date . $sep;
-					print $conf->global->ACCOUNTING_SELL_JOURNAL . $sep;
+					print $sell_journal . $sep;
 					print length_accountg(html_entity_decode($k)) . $sep;
 					print $sep;
 					print ($mt < 0 ? 'D' : 'C') . $sep;
@@ -289,11 +292,12 @@ if ($action == 'export_csv') {
 					print "\n";
 				}
 			}
+
 			// TVA
 			foreach ( $tabtva[$key] as $k => $mt ) {
 				if ($mt) {
 					print $date . $sep;
-					print $conf->global->ACCOUNTING_SELL_JOURNAL . $sep;
+					print $sell_journal . $sep;
 					print length_accountg(html_entity_decode($k)) . $sep;
 					print $sep;
 					print ($mt < 0 ? 'D' : 'C') . $sep;
@@ -304,7 +308,7 @@ if ($action == 'export_csv') {
 				}
 			}
 		}
-	} else 	// Modèle Export Classique
+	} else 	// Model Classic Export
 	{
 		foreach ( $tabfac as $key => $val ) {
 			$companystatic->id = $tabcompany[$key]['id'];
@@ -312,15 +316,16 @@ if ($action == 'export_csv') {
 			$companystatic->client = $tabcompany[$key]['code_client'];
 
 			$date = dol_print_date($db->jdate($val["date"]), 'day');
-			print '"' . $date . '"' . $sep;
-			print '"' . $val["ref"] . '"' . $sep;
+
 			foreach ( $tabttc[$key] as $k => $mt ) {
+				print '"' . $date . '"' . $sep;
+				print '"' . $val["ref"] . '"' . $sep;
 				print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
 				print '"' . utf8_decode($companystatic->name) . '"' . $sep;
 				print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
 				print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
+				print "\n";
 			}
-			print "\n";
 
 			// Product / Service
 			foreach ( $tabht[$key] as $k => $mt ) {
@@ -339,7 +344,6 @@ if ($action == 'export_csv') {
 			}
 
 			// VAT
-			// var_dump($tabtva);
 			foreach ( $tabtva[$key] as $k => $mt ) {
 				if ($mt) {
 					print '"' . $date . '"' . $sep;
@@ -372,7 +376,7 @@ if ($action == 'export_csv') {
 	$period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1);
 	report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''));
 
-	print '<input type="button" class="button" style="float: right;" value="Export CSV" onclick="launch_export();" />';
+	print '<input type="button" class="button" style="float: right;" value="' . $langs->trans("Export") . '" onclick="launch_export();" />';
 
 	print '<input type="button" class="button" value="' . $langs->trans("WriteBookKeeping") . '" onclick="writebookkeeping();" />';
 
@@ -420,12 +424,11 @@ if ($action == 'export_csv') {
 
 		$date = dol_print_date($db->jdate($val["date"]), 'day');
 
-		print "<tr " . $bc[$var] . ">";
-
 		// Third party
-		print "<td>" . $date . "</td>";
-		print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
 		foreach ( $tabttc[$key] as $k => $mt ) {
+			print "<tr " . $bc[$var] . ">";
+			print "<td>" . $date . "</td>";
+			print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
 			$companystatic->id = $tabcompany[$key]['id'];
 			$companystatic->name = $tabcompany[$key]['name'];
 			$companystatic->client = $tabcompany[$key]['code_client'];
@@ -455,7 +458,6 @@ if ($action == 'export_csv') {
 		}
 
 		// VAT
-		// var_dump($tabtva);
 		foreach ( $tabtva[$key] as $k => $mt ) {
 			if ($mt) {
 				print "<tr " . $bc[$var] . ">";
@@ -473,8 +475,8 @@ if ($action == 'export_csv') {
 	}
 
 	print "</table>";
+
+	// End of page
+	llxFooter();
 }
-// End of page
-llxFooter();
-	
 $db->close();
\ No newline at end of file
diff --git a/htdocs/core/modules/modAccounting.class.php b/htdocs/core/modules/modAccounting.class.php
index d683d4bb271..70a52dc90e1 100644
--- a/htdocs/core/modules/modAccounting.class.php
+++ b/htdocs/core/modules/modAccounting.class.php
@@ -129,7 +129,7 @@ class modAccounting extends DolibarrModules
 		$this->const[9] = array(
 				"ACCOUNTING_EXPORT_MODELCSV",
 				"chaine",
-				"0"
+				"1"
 		);
 		$this->const[10] = array(
 				"ACCOUNTING_LENGTH_GACCOUNT",
diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang
index e1713acd57c..b09dab7f764 100644
--- a/htdocs/langs/en_US/accountancy.lang
+++ b/htdocs/langs/en_US/accountancy.lang
@@ -13,7 +13,9 @@ ConfigAccountingExpert=Configuration of the module accounting expert
 Journaux=Journals
 JournalFinancial=Financial journals
 Exports=Exports
+Export=Export
 Modelcsv=Model of export
+OptionsDeactivatedForThisExportModel=For this export model, options are deactivated
 Selectmodelcsv=Select a model of export
 Modelcsv_normal=Classic export
 Modelcsv_CEGID=Export towards CEGID Expert
@@ -66,7 +68,7 @@ Lineofinvoice=Line of invoice
 VentilatedinAccount=Ventilated successfully in the accounting account
 NotVentilatedinAccount=Not ventilated in the accounting account
 
-ACCOUNTING_SEPARATORCSV=Separator CSV
+ACCOUNTING_SEPARATORCSV=Column separator in export file
 
 ACCOUNTING_LIMIT_LIST_VENTILATION=Number of elements to be breakdown shown by page (maximum recommended : 50)
 ACCOUNTING_LIST_SORT_VENTILATION_TODO=Begin the sorting of the breakdown pages "Has to breakdown" by the most recent elements
-- 
GitLab