From eb7b71e3ab1e2972262b4306348a81881fc55278 Mon Sep 17 00:00:00 2001
From: Florian HENRY <florian.henry@open-concept.pro>
Date: Tue, 2 Feb 2016 11:10:38 +0100
Subject: [PATCH] Fix accountancy

---
 htdocs/accountancy/journal/bankjournal.php    | 50 +++++++++----------
 .../accountancy/journal/purchasesjournal.php  | 13 +++--
 htdocs/accountancy/journal/sellsjournal.php   | 14 +++---
 3 files changed, 40 insertions(+), 37 deletions(-)

diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php
index 47a6eeb14d1..23c22afbb2c 100644
--- a/htdocs/accountancy/journal/bankjournal.php
+++ b/htdocs/accountancy/journal/bankjournal.php
@@ -413,7 +413,8 @@ if ($action == 'export_csv') {
 	
 	$companystatic = new Client($db);
 	
-	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) // Model Cegid Expert Export
+	// Model Cegid Expert Export
+	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) 
 {
 		$sep = ";";
 		
@@ -460,22 +461,20 @@ if ($action == 'export_csv') {
 				}
 			} else {
 				foreach ( $tabbq[$key] as $k => $mt ) {
-					if (1) {
-						print $date . $sep;
-						print $journal . $sep;
-						print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . $sep;
-						print $sep;
-						print ($mt < 0 ? 'D' : 'C') . $sep;
-						print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
-						print $val["type_payment"] . $sep;
-						print $val["ref"] . $sep;
-						print "\n";
-					}
+					print $date . $sep;
+					print $journal . $sep;
+					print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . $sep;
+					print $sep;
+					print ($mt < 0 ? 'D' : 'C') . $sep;
+					print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
+					print $val["type_payment"] . $sep;
+					print $val["ref"] . $sep;
+					print "\n";
 				}
 			}
 		}
-	} else // Model Classic Export
-{
+	} else {
+		// Model Classic Export
 		foreach ( $tabpay as $key => $val ) {
 			$date = dol_print_date($db->jdate($val["date"]), 'day');
 			
@@ -508,15 +507,13 @@ if ($action == 'export_csv') {
 				}
 			} else {
 				foreach ( $tabbq[$key] as $k => $mt ) {
-					if (1) {
-						print '"' . $date . '"' . $sep;
-						print '"' . $val["ref"] . '"' . $sep;
-						print '"' . length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . '"' . $sep;
-						print '"' . $langs->trans("Bank") . '"' . $sep;
-						print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
-						print '"' . ($mt >= 0 ? price($mt) : '') . '"';
-						print "\n";
-					}
+					print '"' . $date . '"' . $sep;
+					print '"' . $val["ref"] . '"' . $sep;
+					print '"' . length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . '"' . $sep;
+					print '"' . $langs->trans("Bank") . '"' . $sep;
+					print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
+					print '"' . ($mt >= 0 ? price($mt) : '') . '"';
+					print "\n";
 				}
 			}
 		}
@@ -532,7 +529,6 @@ 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);
 	
 	$varlink = 'id_account=' . $id_bank_account;
-	
 	report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array (
 			'action' => '' 
 	), '', $varlink);
@@ -577,10 +573,12 @@ if ($action == 'export_csv') {
 	foreach ( $tabpay as $key => $val ) {
 		$date = dol_print_date($db->jdate($val["date"]), 'day');
 		
-		if ($val["lib"] == '(SupplierInvoicePayment)')
+		if ($val["lib"] == '(SupplierInvoicePayment)') {
 			$reflabel = $langs->trans('SupplierInvoicePayment');
-		if ($val["lib"] == '(CustomerInvoicePayment)')
+		}
+		if ($val["lib"] == '(CustomerInvoicePayment)') {
 			$reflabel = $langs->trans('CustomerInvoicePayment');
+		}
 			
 			// Bank
 		foreach ( $tabbq[$key] as $k => $mt ) {
diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php
index c4ab3b1709e..d5a5e1d1fb1 100644
--- a/htdocs/accountancy/journal/purchasesjournal.php
+++ b/htdocs/accountancy/journal/purchasesjournal.php
@@ -267,7 +267,8 @@ if ($action == 'export_csv') {
 	
 	include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
 	
-	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) // Model Cegid Expert Export
+	// Model Cegid Expert Export
+	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) 
 {
 		$sep = ";";
 		
@@ -320,8 +321,8 @@ if ($action == 'export_csv') {
 				print "\n";
 			}
 		}
-	} else // Model Classic Export
-{
+	} else {
+		// Model Classic Export
 		foreach ( $tabfac as $key => $val ) {
 			$date = dol_print_date($db->jdate($val["date"]), 'day');
 			
@@ -380,10 +381,12 @@ if ($action == 'export_csv') {
 	$exportlink = '';
 	$builddate = time();
 	$description = $langs->trans("DescPurchasesJournal") . '<br>';
-	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS))
+	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
 		$description .= $langs->trans("DepositsAreNotIncluded");
-	else
+	} else {
 		$description .= $langs->trans("DepositsAreIncluded");
+	}
+	
 	$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' => '' 
diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php
index af77d3e0c06..4545ac9578b 100644
--- a/htdocs/accountancy/journal/sellsjournal.php
+++ b/htdocs/accountancy/journal/sellsjournal.php
@@ -287,13 +287,14 @@ if ($action == 'writebookkeeping') {
 // Export
 if ($action == 'export_csv') {
 	$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
-	$journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
+	$sell_journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
 	
 	include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
 	
 	$companystatic = new Client($db);
 	
-	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) // Model Cegid Expert Export
+	// Model Cegid Expert Export
+	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) 
 {
 		$sep = ";";
 		
@@ -318,14 +319,15 @@ if ($action == 'export_csv') {
 			
 			// Product / Service
 			foreach ( $tabht[$key] as $k => $mt ) {
-				if ($mt) {
+				$accountingaccount_static = new AccountingAccount($db);
+				if ($accountingaccount_static->fetch(null, $k)) {
 					print $date . $sep;
 					print $sell_journal . $sep;
 					print length_accountg(html_entity_decode($k)) . $sep;
 					print $sep;
 					print ($mt < 0 ? 'D' : 'C') . $sep;
 					print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
-					print dol_trunc($val["description"], 32) . $sep;
+					print dol_trunc($accountingaccount_static->label, 32) . $sep;
 					print $val["ref"];
 					print "\n";
 				}
@@ -346,8 +348,8 @@ if ($action == 'export_csv') {
 				}
 			}
 		}
-	} else // Model Classic Export
-{
+	} else {
+		// Model Classic Export
 		foreach ( $tabfac as $key => $val ) {
 			$companystatic->id = $tabcompany[$key]['id'];
 			$companystatic->name = $tabcompany[$key]['name'];
-- 
GitLab