From 94a9d0159d156ecedecbaa33ff102713768129af Mon Sep 17 00:00:00 2001
From: aspangaro <alexandre.spangaro@gmail.com>
Date: Sun, 25 Jan 2015 15:24:16 +0100
Subject: [PATCH] Align module with 3.7 & contrary

---
 .../bookkeeping/balancebymonth.php            |  6 +--
 htdocs/accountancy/bookkeeping/list.php       |  6 +--
 htdocs/accountancy/bookkeeping/listbyyear.php |  7 ++-
 .../class/accountingaccount.class.php         |  1 -
 .../class/html.formventilation.class.php      |  2 +-
 htdocs/accountancy/customer/card.php          |  7 ++-
 htdocs/accountancy/customer/index.php         | 14 ++++--
 htdocs/accountancy/customer/lines.php         |  6 +--
 htdocs/accountancy/customer/list.php          | 24 ++++++++--
 htdocs/accountancy/journal/bankjournal.php    |  4 +-
 htdocs/accountancy/journal/cashjournal.php    |  4 +-
 .../accountancy/journal/purchasesjournal.php  | 20 +++++----
 htdocs/accountancy/journal/sellsjournal.php   | 28 +++++++-----
 htdocs/accountancy/supplier/card.php          |  2 +-
 htdocs/accountancy/supplier/index.php         |  8 ++--
 htdocs/accountancy/supplier/lines.php         | 12 ++---
 htdocs/accountancy/supplier/list.php          | 45 ++++++++++++++++---
 17 files changed, 129 insertions(+), 67 deletions(-)

diff --git a/htdocs/accountancy/bookkeeping/balancebymonth.php b/htdocs/accountancy/bookkeeping/balancebymonth.php
index 120d08db09c..35e6c85ee4f 100644
--- a/htdocs/accountancy/bookkeeping/balancebymonth.php
+++ b/htdocs/accountancy/bookkeeping/balancebymonth.php
@@ -50,10 +50,10 @@ if ($year == 0) {
 /*
  * View
  */
-llxHeader('', $langs->trans("CustomersVentilation"));
+llxHeader('', $langs->trans("Bookkeeping"));
 
-$textprevyear = "<a href=\"balancebymonth.php?year=" . ($year_current - 1) . "\">" . img_previous() . "</a>";
-$textnextyear = " <a href=\"balancebymonth.php?year=" . ($year_current + 1) . "\">" . img_next() . "</a>";
+$textprevyear = '<a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year_current - 1) . '">' . img_previous() . '</a>';
+$textnextyear = '&nbsp;<a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year_current + 1) . '">' . img_next() . '</a>';
 
 print_fiche_titre($langs->trans("AccountBalanceByMonth") . ' ' . $textprevyear . ' ' . $langs->trans("Year") . ' ' . $year_start . ' ' . $textnextyear);
 
diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php
index b2acc60fb6a..83ff8cdad14 100644
--- a/htdocs/accountancy/bookkeeping/list.php
+++ b/htdocs/accountancy/bookkeeping/list.php
@@ -151,7 +151,7 @@ else {
 		
 		print $formventilation->select_bookkeeping_importkey('importkey', GETPOST('importkey'));
 		
-		print '<div class="inline-block divButAction"><input type="submit" class="butAction" value="' . $langs->trans("DelBookKeeping") . '" />';
+		print '<div class="inline-block divButAction"><input type="submit" class="butAction" value="' . $langs->trans("DelBookKeeping") . '" /></div>';
 		
 		print '</form>';
 		
@@ -171,7 +171,7 @@ else {
 		print_liste_field_titre($langs->trans("Numerocompte"), $_SERVER['PHP_SELF'], "bk.numero_compte", "", "", "", $sortfield, $sortorder);
 		print_liste_field_titre($langs->trans("Code_tiers"), $_SERVER['PHP_SELF'], "bk.code_tiers", "", "", "", $sortfield, $sortorder);
 		print_liste_field_titre($langs->trans("Labelcompte"), $_SERVER['PHP_SELF'], "bk_label_compte", "", "", "", $sortfield, $sortorder);
-		print_liste_field_titre($langs->trans("Debit"), $_SERVER['PHP_SELF'], "bk.debit", "", "", 'align="center"', $sortfield, $sortorder);
+		print_liste_field_titre($langs->trans("Debit"), $_SERVER['PHP_SELF'], "bk.debit", "", "", align="center"', $sortfield, $sortorder);
 		print_liste_field_titre($langs->trans("Credit"), $_SERVER['PHP_SELF'], "bk.credit", "", "", 'align="center"', $sortfield, $sortorder);
 		print_liste_field_titre($langs->trans("Amount"), $_SERVER['PHP_SELF'], "bk.montant", "", "", 'align="center"', $sortfield, $sortorder);
 		print_liste_field_titre($langs->trans("Sens"), $_SERVER['PHP_SELF'], "bk.sens", "", "", 'align="center"', $sortfield, $sortorder);
@@ -231,4 +231,4 @@ else {
 }
 
 llxFooter();
-$db->close();
+$db->close();
\ No newline at end of file
diff --git a/htdocs/accountancy/bookkeeping/listbyyear.php b/htdocs/accountancy/bookkeeping/listbyyear.php
index 0829f792130..26f0469c1a0 100644
--- a/htdocs/accountancy/bookkeeping/listbyyear.php
+++ b/htdocs/accountancy/bookkeeping/listbyyear.php
@@ -56,12 +56,11 @@ $offset = $conf->liste_limit * $page;
 
 llxHeader('', $langs->trans("Bookkeeping"));
 
-$textprevyear = "<a href=\"listbyyear.php?year=" . ($year_current - 1) . "\">" . img_previous() . "</a>";
-$textnextyear = " <a href=\"listbyyear.php?year=" . ($year_current + 1) . "\">" . img_next() . "</a>";
+$textprevyear = '<a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year_current - 1) . '">' . img_previous() . '</a>';
+$textnextyear = '&nbsp;<a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year_current + 1) . '">' . img_next() . '</a>';
 
 /*
- * Mode Liste
- *
+ * Mode List
  */
 
 $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, bk.code_tiers, bk.numero_compte , bk.label_compte, bk.debit , bk.credit, bk.montant , bk.sens, bk.code_journal";
diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php
index 46a34698785..24031b683b4 100644
--- a/htdocs/accountancy/class/accountingaccount.class.php
+++ b/htdocs/accountancy/class/accountingaccount.class.php
@@ -53,7 +53,6 @@ class AccountingAccount
 	 * @param 	DoliDB	$db		Database handle
 	 */
 	function __construct($db)
-
 	{
 		$this->db = $db;
 	}
diff --git a/htdocs/accountancy/class/html.formventilation.class.php b/htdocs/accountancy/class/html.formventilation.class.php
index 33bb33a2353..4e833862bd8 100644
--- a/htdocs/accountancy/class/html.formventilation.class.php
+++ b/htdocs/accountancy/class/html.formventilation.class.php
@@ -128,7 +128,7 @@ class FormVentilation extends Form
 					$label = $obj->account_number . ' - ' . $obj->label;
 
 					// Remember guy's we store in database llx_facturedet the rowid of accountingaccount and not the account_number
-					// Bacause same account_number can be share between different accounting_system and do have the same meaning
+					// Because same account_number can be share between different accounting_system and do have the same meaning
 					if (($selectid != '') && $selectid == $obj->rowid) {
 						// $out .= '<option value="' . $obj->account_number . '" selected="selected">' . $label . '</option>';
 						$out .= '<option value="' . $obj->rowid . '" selected="selected">' . $label . '</option>';
diff --git a/htdocs/accountancy/customer/card.php b/htdocs/accountancy/customer/card.php
index 28d3d0c1f79..9eb546ec89d 100644
--- a/htdocs/accountancy/customer/card.php
+++ b/htdocs/accountancy/customer/card.php
@@ -45,8 +45,7 @@ if ($user->societe_id > 0)
  * Actions
  */
 
-if ($action == 'ventil' && $user->rights->accounting->ventilation->dispatch) 
-{
+if ($action == 'ventil' && $user->rights->accounting->ventilation->dispatch) {
 	if (! GETPOST('cancel', 'alpha'))
 	{
 		$sql = " UPDATE " . MAIN_DB_PREFIX . "facturedet";
@@ -127,8 +126,8 @@ if (! empty($id)) {
 			print '</td></tr>';
 			print '</table>';
 			
-			print '<br><center><input class="button" type="submit" value="' . $langs->trans("Save") . '"> &nbsp; &nbsp; ';
-			print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '"></center';
+			print '<br><div align="center"><input class="button" type="submit" value="' . $langs->trans("Save") . '">&nbsp;&nbsp;&nbsp;&nbsp;';
+			print '<input class="button" type="submit" name="cancel" value="' . $langs->trans("Cancel") . '"></div>';
 	
 			print '</form>';
 		} else {
diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php
index 663e763a9d3..1760f8360a9 100644
--- a/htdocs/accountancy/customer/index.php
+++ b/htdocs/accountancy/customer/index.php
@@ -22,7 +22,7 @@
 /**
  * \file		htdocs/accountancy/customer/index.php
  * \ingroup		Accounting Expert
- * \brief		Page accueil clients ventilation comptable
+ * \brief		Home customer ventilation
  */
 
 require '../../main.inc.php';
@@ -75,6 +75,8 @@ if ($action == 'validatehistory') {
 		$sql1 .= " AND accnt.active = 1 AND p.accountancy_code_sell=accnt.account_number";
 		$sql1 .= " AND fd.fk_code_ventilation = 0";
 	}
+	
+	dol_syslog("htdocs/accountancy/customer/index.php sql=" . $sql, LOG_DEBUG);
 
 	$resql1 = $db->query($sql1);
 	if (! $resql1) {
@@ -93,7 +95,7 @@ if ($action == 'validatehistory') {
 llxHeader('', $langs->trans("CustomersVentilation"));
 
 $textprevyear = '<a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year_current - 1) . '">' . img_previous() . '</a>';
-$textnextyear = ' <a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year_current + 1) . '">' . img_next() . '</a>';
+$textnextyear = '&nbsp;<a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year_current + 1) . '">' . img_next() . '</a>';
 
 print_fiche_titre($langs->trans("CustomersVentilation") . " " . $textprevyear . " " . $langs->trans("Year") . " " . $year_start . " " . $textnextyear);
 
@@ -105,6 +107,7 @@ $sql .= " , " . MAIN_DB_PREFIX . "facture as f";
 $sql .= " WHERE fd.fk_code_ventilation = 0";
 $sql .= " AND f.rowid = fd.fk_facture AND f.fk_statut = 1;";
 
+dol_syslog("htdocs/accountancy/customer/index.php sql=" . $sql, LOG_DEBUG);
 $result = $db->query($sql);
 if ($result) {
 	$row = $db->fetch_row($result);
@@ -160,6 +163,7 @@ if (! empty($conf->multicompany->enabled)) {
 
 $sql .= " GROUP BY fd.fk_code_ventilation";
 
+dol_syslog("htdocs/accountancy/customer/index.php sql=" . $sql, LOG_DEBUG);
 $resql = $db->query($sql);
 if ($resql) {
 	$i = 0;
@@ -194,7 +198,7 @@ print "</table>\n";
 
 print "<br>\n";
 print '<table class="noborder" width="100%">';
-print '<tr class="liste_titre"><td width="400" align="left">' . $langs->trans("Total") . '</td>';
+print '<tr class="liste_titre"><td width="400" align="left">' . $langs->trans("TotalVente") . '</td>';
 print '<td width="60" align="center">' . $langs->trans("JanuaryMin") . '</td>';
 print '<td width="60" align="center">' . $langs->trans("FebruaryMin") . '</td>';
 print '<td width="60" align="center">' . $langs->trans("MarchMin") . '</td>';
@@ -232,6 +236,7 @@ if (! empty($conf->multicompany->enabled)) {
 	$sql .= " AND f.entity = '" . $conf->entity . "'";
 }
 
+dol_syslog('htdocs/accountancy/customer/index.php:: $sql=' . $sql);
 $resql = $db->query($sql);
 if ($resql) {
 	$i = 0;
@@ -303,7 +308,8 @@ if (! empty($conf->margin->enabled)) {
 	if (! empty($conf->multicompany->enabled)) {
 		$sql .= " AND f.entity = '" . $conf->entity . "'";
 	}
-
+	
+	dol_syslog('htdocs/accountancy/customer/index.php:: $sql=' . $sql);
 	$resql = $db->query($sql);
 	if ($resql) {
 		$i = 0;
diff --git a/htdocs/accountancy/customer/lines.php b/htdocs/accountancy/customer/lines.php
index 9215d5a9d98..01806db8332 100644
--- a/htdocs/accountancy/customer/lines.php
+++ b/htdocs/accountancy/customer/lines.php
@@ -133,7 +133,7 @@ if ($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE > 0) {
 }
 $sql .= $db->plimit($limit + 1, $offset);
 
-dol_syslog("/accountancy/customer/linges.php sql=" . $sql, LOG_DEBUG);
+dol_syslog("/accountancy/customer/lines.php sql=" . $sql, LOG_DEBUG);
 $result = $db->query($sql);
 if ($result) {
 	$num_lines = $db->num_rows($result);
@@ -220,5 +220,5 @@ if ($result) {
 
 print "</table></form>";
 
-$db->close();
-llxFooter();
\ No newline at end of file
+llxFooter();
+$db->close();
\ No newline at end of file
diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php
index 3b68bd6b69e..8ee5eb41eb5 100644
--- a/htdocs/accountancy/customer/list.php
+++ b/htdocs/accountancy/customer/list.php
@@ -52,9 +52,25 @@ $formventilation = new FormVentilation($db);
 
 llxHeader('', $langs->trans("Ventilation"));
 
+print  '<script type="text/javascript">
+			$(function () {
+				$(\'#select-all\').click(function(event) {
+				    // Iterate each checkbox
+				    $(\':checkbox\').each(function() {
+				    	this.checked = true;
+				    });
+			    });
+			    $(\'#unselect-all\').click(function(event) {
+				    // Iterate each checkbox
+				    $(\':checkbox\').each(function() {
+				    	this.checked = false;
+				    });
+			    });
+			});
+			 </script>';
 /*
  * Action
-*/
+ */
 
 if ($action == 'ventil') {
 	print '<div><font color="red">' . $langs->trans("Processing") . '...</font></div>';
@@ -113,8 +129,8 @@ $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facturedet as l ON f.rowid = l.fk_fac
 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accountingaccount as aa ON p.accountancy_code_sell = aa.account_number";
 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_system as accsys ON accsys.pcg_version = aa.fk_pcg_version";
-$sql .= " WHERE f.fk_statut > 0 AND fk_code_ventilation = 0";
-$sql .= " AND (accsys.rowid='".$conf->global->CHARTOFACCOUNTS."' OR p.accountancy_code_sell IS NULL)";
+$sql .= " WHERE f.fk_statut > 0 AND fk_code_ventilation <= 0";
+$sql .= " AND (accsys.rowid='" . $conf->global->CHARTOFACCOUNTS . "' OR p.accountancy_code_sell IS NULL OR p.accountancy_code_sell ='')";
 if (! empty($conf->multicompany->enabled)) {
 	$sql .= " AND f.entity = '" . $conf->entity . "'";
 }
@@ -147,7 +163,7 @@ if ($result) {
 	print '<td align="right">' . $langs->trans("Amount") . '</td>';
 	print '<td align="right">' . $langs->trans("AccountAccounting") . '</td>';
 	print '<td align="center">' . $langs->trans("IntoAccount") . '</td>';
-	print '<td align="center">' . $langs->trans("Ventilate") . '</td>';
+	print '<td align="center">' . $langs->trans("Ventilate") . '<br><label id="select-all">'.$langs->trans('All').'</label>/<label id="unselect-all">'.$langs->trans('None').'</label>'.'</td>';
 	print '</tr>';
 
 	$facture_static = new Facture($db);
diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php
index 1f9b0549121..95a00eaf950 100644
--- a/htdocs/accountancy/journal/bankjournal.php
+++ b/htdocs/accountancy/journal/bankjournal.php
@@ -404,14 +404,14 @@ if ($action == 'writeBookKeeping')
 // export csv
 if ($action == 'export_csv')
 {
-	$sep = $conf->global->ACCOUNTING_SEPARATORCSV;
+	$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
 
 	header('Content-Type: text/csv');
 	header('Content-Disposition: attachment;filename=journal_banque.csv');
 
 	$companystatic = new Client($db);
 
-	if ($conf->global->ACCOUNTING_MODELCSV == 1) 	// Modèle Export Cegid Expert
+	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) 	// Modèle Export Cegid Expert
 	{
 		foreach ( $tabpay as $key => $val ) {
 			$date = dol_print_date($db->jdate($val["date"]), '%d%m%Y');
diff --git a/htdocs/accountancy/journal/cashjournal.php b/htdocs/accountancy/journal/cashjournal.php
index fb5a15a513c..51b8625f9b3 100644
--- a/htdocs/accountancy/journal/cashjournal.php
+++ b/htdocs/accountancy/journal/cashjournal.php
@@ -367,12 +367,12 @@ if ($action == 'writeBookKeeping') {
 }
 // export csv
 if ($action == 'export_csv') {
-	$sep = $conf->global->ACCOUNTING_SEPARATORCSV;
+	$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
 
 	header('Content-Type: text/csv');
 	header('Content-Disposition:attachment;filename=journal_caisse.csv');
 
-	if ($conf->global->ACCOUNTING_MODELCSV == 1) 	// Modèle Export Cegid Expert
+	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) 	// Modèle Export Cegid Expert
 	{
 		foreach ( $tabpay as $key => $val ) {
 			$date = dol_print_date($db->jdate($val["date"]), '%d%m%Y');
diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php
index d2f204c6b8c..68bcdaa394f 100644
--- a/htdocs/accountancy/journal/purchasesjournal.php
+++ b/htdocs/accountancy/journal/purchasesjournal.php
@@ -185,8 +185,8 @@ if ($action == 'writebookkeeping') {
 		foreach ( $tabht[$key] as $k => $mt ) {
 			if ($mt) {
 				// get compte id and label
-				$compte = new AccountingAccount($db);
-				if ($compte->fetch(null, $k)) {
+				$accountingaccount = new AccountingAccount($db);
+				if ($accountingaccount->fetch(null, $k)) {
 					$bookkeeping = new BookKeeping($db);
 					$bookkeeping->doc_date = $val["date"];
 					$bookkeeping->doc_ref = $val["ref"];
@@ -195,7 +195,7 @@ if ($action == 'writebookkeeping') {
 					$bookkeeping->fk_doc = $key;
 					$bookkeeping->fk_docdet = $val["fk_facturefourndet"];
 					$bookkeeping->code_tiers = '';
-					$bookkeeping->label_compte = dol_trunc($val["description"], 128);
+					$bookkeeping->label_compte = $accountingaccount->label;
 					$bookkeeping->numero_compte = $k;
 					$bookkeeping->montant = $mt;
 					$bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
@@ -213,7 +213,6 @@ if ($action == 'writebookkeeping') {
 		foreach ( $tabtva[$key] as $k => $mt ) {
 			if ($mt) {
 				// get compte id and label
-
 				$bookkeeping = new BookKeeping($db);
 				$bookkeeping->doc_date = $val["date"];
 				$bookkeeping->doc_ref = $val["ref"];
@@ -246,12 +245,12 @@ $companystatic = new Societe($db);
 // export csv
 if ($action == 'export_csv')
 {
-	$sep = $conf->global->ACCOUNTING_SEPARATORCSV;
+	$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
 
 	header('Content-Type: text/csv');
 	header('Content-Disposition: attachment;filename=journal_achats.csv');
 
-	if ($conf->global->ACCOUNTING_MODELCSV == 1) 	// Modèle Export Cegid Expert
+	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) 	// Modèle Export Cegid Expert
 	{
 		foreach ( $tabfac as $key => $val ) {
 			$date = dol_print_date($db->jdate($val["date"]), '%d%m%Y');
@@ -314,11 +313,13 @@ if ($action == 'export_csv')
 
 			// Product / Service
 			foreach ( $tabht[$key] as $k => $mt ) {
+			$accountingaccount = new AccountingAccount($db);
+		    $accountingaccount->fetch(null, $k);	
 				if ($mt) {
 					print '"' . $date . '"' . $sep;
 					print '"' . $val["ref"] . '"' . $sep;
 					print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
-					print '"' . dol_trunc($val["description"], 32) . '"' . $sep;
+					print '"' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
 					print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
 					print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
 					print "\n";
@@ -418,12 +419,15 @@ if ($action == 'export_csv')
 
 		// Product / Service
 		foreach ( $tabht[$key] as $k => $mt ) {
+		$accountingaccount = new AccountingAccount($db);
+		$accountingaccount->fetch(null, $k);
+
 			if ($mt) {
 				print "<tr " . $bc[$var] . " >";
 				print "<td>" . $date . "</td>";
 				print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
 				print "<td>" . length_accountg($k) . "</td>";
-				print "<td>" . $invoicestatic->description . "</td>";
+				print "<td>" . $accountingaccount->label . "</td>";
 				print '<td align="right">' . ($mt >= 0 ? price($mt) : '') . "</td>";
 				print '<td align="right">' . ($mt < 0 ? price(- $mt) : '') . "</td>";
 				print "</tr>";
diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php
index 5bb1f989a92..892272d6a5a 100644
--- a/htdocs/accountancy/journal/sellsjournal.php
+++ b/htdocs/accountancy/journal/sellsjournal.php
@@ -140,7 +140,7 @@ if ($result) {
 		$tabfac[$obj->rowid]["date"] = $obj->df;
 		$tabfac[$obj->rowid]["ref"] = $obj->facnumber;
 		$tabfac[$obj->rowid]["type"] = $obj->type;
-		$tabfac[$obj->rowid]["description"] = $obj->description;
+		$tabfac[$obj->rowid]["description"] = $obj->label_compte;
 		$tabfac[$obj->rowid]["fk_facturedet"] = $obj->fdid;
 		if (! isset($tabttc[$obj->rowid][$compta_soc]))
 			$tabttc[$obj->rowid][$compta_soc] = 0;
@@ -196,8 +196,8 @@ if ($action == 'writebookkeeping') {
 		foreach ( $tabht[$key] as $k => $mt ) {
 			if ($mt) {
 				// get compte id and label
-				$compte = new AccountingAccount($db);
-				if ($compte->fetch(null, $k)) {
+				$accountingaccount = new AccountingAccount($db);
+				if ($accountingaccount->fetch(null, $k)) {
 					$bookkeeping = new BookKeeping($db);
 					$bookkeeping->doc_date = $val["date"];
 					$bookkeeping->doc_ref = $val["ref"];
@@ -207,7 +207,7 @@ if ($action == 'writebookkeeping') {
 					$bookkeeping->fk_docdet = $val["fk_facturedet"];
 					$bookkeeping->code_tiers = '';
 					$bookkeeping->numero_compte = $k;
-					$bookkeeping->label_compte = dol_trunc($val["description"], 128);
+					$bookkeeping->label_compte = $accountingaccount->label;
 					$bookkeeping->montant = $mt;
 					$bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
 					$bookkeeping->debit = ($mt < 0) ? $mt : 0;
@@ -247,14 +247,14 @@ if ($action == 'writebookkeeping') {
 }
 // export csv
 if ($action == 'export_csv') {
-	$sep = $conf->global->ACCOUNTING_SEPARATORCSV;
+	$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
 
 	header('Content-Type: text/csv');
 	header('Content-Disposition: attachment;filename=journal_ventes.csv');
 
 	$companystatic = new Client($db);
 
-	if ($conf->global->ACCOUNTING_MODELCSV == 1) 	// Modèle Export Cegid Expert
+	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) 	// Modèle Export Cegid Expert
 	{
 		foreach ( $tabfac as $key => $val ) {
 			$companystatic->id = $tabcompany[$key]['id'];
@@ -324,11 +324,14 @@ if ($action == 'export_csv') {
 
 			// Product / Service
 			foreach ( $tabht[$key] as $k => $mt ) {
+				$accountingaccount = new AccountingAccount($db);
+				$accountingaccount->fetch(null, $k);
+				
 				if ($mt) {
 					print '"' . $date . '"' . $sep;
 					print '"' . $val["ref"] . '"' . $sep;
 					print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
-					print '"' . dol_trunc($val["description"], 32) . '"' . $sep;
+					print '"' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
 					print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
 					print '"' . ($mt >= 0 ? price($mt) : '') . '"';
 					print "\n";
@@ -436,12 +439,15 @@ if ($action == 'export_csv') {
 
 		// Product / Service
 		foreach ( $tabht[$key] as $k => $mt ) {
+			$accountingaccount = new AccountingAccount($db);
+			$accountingaccount->fetch(null, $k);
+		
 			if ($mt) {
 				print "<tr " . $bc[$var] . ">";
 				print "<td>" . $date . "</td>";
 				print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
 				print "<td>" . length_accountg($k) . "</td>";
-				print "<td>" . $invoicestatic->description . "</td>";
+				print "<td>" . $accountingaccount->label . "</td>";
 				print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>";
 				print "<td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>";
 				print "</tr>";
@@ -467,8 +473,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/accountancy/supplier/card.php b/htdocs/accountancy/supplier/card.php
index 45c8de9b165..1acd5829c45 100644
--- a/htdocs/accountancy/supplier/card.php
+++ b/htdocs/accountancy/supplier/card.php
@@ -4,7 +4,7 @@
  * Copyright (C) 2013-2014  Alexandre Spangaro    <alexandre.spangaro@gmail.com>
  * Copyright (C) 2013-2014  Olivier Geffroy       <jeff@jeffinfo.com>
  * Copyright (C) 2013-2014	Florian Henry	      <florian.henry@open-concept.pro>
- * Copyright (C) 2014	    Juanjo Menent		s<jmenent@2byte.es>
+ * Copyright (C) 2014	    Juanjo Menent		  <jmenent@2byte.es>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
diff --git a/htdocs/accountancy/supplier/index.php b/htdocs/accountancy/supplier/index.php
index edebcfd9d46..85d1c04cf53 100644
--- a/htdocs/accountancy/supplier/index.php
+++ b/htdocs/accountancy/supplier/index.php
@@ -21,7 +21,7 @@
 /**
  * \file		htdocs/accountancy/supplier/index.php
  * \ingroup		Accounting Expert
- * \brief		Page accueil ventilation
+ * \brief		Home supplier ventilation
  */
 
 require '../../main.inc.php';
@@ -93,9 +93,9 @@ if ($action == 'validatehistory') {
 llxHeader('', $langs->trans("SuppliersVentilation"));
 
 $textprevyear = '<a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year_current - 1) . '">' . img_previous() . '</a>';
-$textnextyear = ' <a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year_current + 1) . '">' . img_next() . '</a>';
+$textnextyear = '&nbsp;<a href="' . $_SERVER["PHP_SELF"] . '?year=' . ($year_current + 1) . '">' . img_next() . '</a>';
 
-print_fiche_titre($langs->trans("SuppliersVentilation") . " " . $textprevyear . " " . $langs->trans("Year") . " " . $year_start . " " . $textnextyear);
+print_fiche_titre($langs->trans("SuppliersVentilation") . "&nbsp;" . $textprevyear . "&nbsp;" . $langs->trans("Year") . "&nbsp;" . $year_start . "&nbsp;" . $textnextyear);
 
 print '<b>' . $langs->trans("DescVentilSupplier") . '</b>';
 print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=validatehistory">' . $langs->trans("ValidateHistory") . '</a></div>';
@@ -105,7 +105,7 @@ $y = $year_current;
 $var = true;
 
 print '<table class="noborder" width="100%">';
-print '<tr class="liste_titre"><td width="200">' . $langs->trans("Account") . '</td>';
+print '<tr class="liste_titre"><td width="200" align="left">' . $langs->trans("Account") . '</td>';
 print '<td width="200" align="left">' . $langs->trans("Label") . '</td>';
 print '<td width="60" align="center">' . $langs->trans("JanuaryMin") . '</td>';
 print '<td width="60" align="center">' . $langs->trans("FebruaryMin") . '</td>';
diff --git a/htdocs/accountancy/supplier/lines.php b/htdocs/accountancy/supplier/lines.php
index 8b2a870220d..5df5ee0c06f 100644
--- a/htdocs/accountancy/supplier/lines.php
+++ b/htdocs/accountancy/supplier/lines.php
@@ -1,7 +1,5 @@
 <?php
-/* Copyright (C) 2002-2005 Rodolphe Quiedeville	<rodolphe@quiedeville.org>
- * Copyright (C) 2005      Simon TOSSER			<simon@kornog-computing.com>
- * Copyright (C) 2013-2014 Olivier Geffroy		<jeff@jeffinfo.com>
+/* Copyright (C) 2013-2014 Olivier Geffroy		<jeff@jeffinfo.com>
  * Copyright (C) 2013-2014 Alexandre Spangaro	<alexandre.spangaro@gmail.com>
  * Copyright (C) 2014      Ari Elbaz (elarifr)	<github@accedinfo.com>  
  * Copyright (C) 2013-2014 Florian Henry		<florian.henry@open-concept.pro>
@@ -48,6 +46,7 @@ if ($user->societe_id > 0)
 if (! $user->rights->accounting->ventilation->dispatch)
 	accessforbidden();
 
+
 $formventilation = new FormVentilation($db);
 
 $changeaccount = GETPOST('changeaccount');
@@ -107,7 +106,7 @@ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product
 $sql .= " WHERE f.rowid = l.fk_facture_fourn and f.fk_statut >= 1 AND l.fk_code_ventilation <> 0 ";
 $sql .= " AND aa.rowid = l.fk_code_ventilation";
 if (strlen(trim($_GET["search_facture"]))) {
-	$sql .= " AND f.facnumber like '%" . $_GET["search_facture"] . "%'";
+	$sql .= " AND f.ref like '%" . $_GET["search_facture"] . "%'";
 }
 if (strlen(trim($_GET["search_ref"]))) {
 	$sql .= " AND p.ref like '%" . $_GET["search_ref"] . "%'";
@@ -218,7 +217,8 @@ if ($result) {
 	print $db->error();
 }
 
+
 print "</table></form>";
 
-$db->close();
-llxFooter();
\ No newline at end of file
+llxFooter();
+$db->close();
\ No newline at end of file
diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php
index f932fbfc8af..a85dd7a17d4 100644
--- a/htdocs/accountancy/supplier/list.php
+++ b/htdocs/accountancy/supplier/list.php
@@ -22,7 +22,7 @@
 /**
  * \file		htdocs/accountancy/supplier/list.php
  * \ingroup		Accounting Expert
- * \brief		Page de ventilation des lignes de facture
+ * \brief		Ventilation page from suppliers invoices
  */
 
 require '../../main.inc.php';
@@ -53,6 +53,22 @@ $formventilation = new FormVentilation($db);
 
 llxHeader('', $langs->trans("Ventilation"));
 
+print  '<script type="text/javascript">
+			$(function () {
+				$(\'#select-all\').click(function(event) {
+				    // Iterate each checkbox
+				    $(\':checkbox\').each(function() {
+				    	this.checked = true;
+				    });
+			    });
+			    $(\'#unselect-all\').click(function(event) {
+				    // Iterate each checkbox
+				    $(\':checkbox\').each(function() {
+				    	this.checked = false;
+				    });
+			    });
+			});
+			 </script>';
 /*
  * Action
  */
@@ -115,8 +131,8 @@ $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture_fourn_det as l ON f.rowid = l
 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = l.fk_product";
 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accountingaccount as aa ON p.accountancy_code_buy = aa.account_number";
 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_system as accsys ON accsys.pcg_version = aa.fk_pcg_version";
-$sql .= " WHERE f.fk_statut > 0 AND fk_code_ventilation = 0";
-$sql .= " AND (accsys.rowid='".$conf->global->CHARTOFACCOUNTS."' OR p.accountancy_code_sell IS NULL)";
+$sql .= " WHERE f.fk_statut > 0 AND fk_code_ventilation <= 0";
+$sql .= " AND (accsys.rowid='".$conf->global->CHARTOFACCOUNTS."' OR p.accountancy_code_sell IS NULL OR p.accountancy_code_buy ='')";
 
 if (! empty($conf->multicompany->enabled)) {
 	$sql .= " AND f.entity = '" . $conf->entity . "'";
@@ -150,7 +166,7 @@ if ($result) {
 	print '<td align="right">' . $langs->trans("Amount") . '</td>';
 	print '<td align="right">' . $langs->trans("Compte") . '</td>';
 	print '<td align="center">' . $langs->trans("IntoAccount") . '</td>';
-	print '<td align="center">' . $langs->trans("Ventilate") . '</td>';
+	print '<td align="center">' . $langs->trans("Ventilate") . '<br><label id="select-all">'.$langs->trans('All').'</label>/<label id="unselect-all">'.$langs->trans('None').'</label>'.'</td>';
 	print "</tr>\n";
 
 	$facturefourn_static = new FactureFournisseur($db);
@@ -161,6 +177,23 @@ if ($result) {
 	while ( $i < min($num_lines, $limit) ) {
 		$objp = $db->fetch_object($result);
 		$var = ! $var;
+		
+		// product_type: 0 = service ? 1 = product
+		// if product does not exist we use the value of product_type provided in facturedet to define if this is a product or service
+		// issue : if we change product_type value in product DB it should differ from the value stored in facturedet DB !
+		$code_buy_notset = '';
+		
+		if (empty($objp->code_buy)) {
+			$code_buy_notset = 'color:red';
+			if ($objp->type == 1) {
+				$objp->code_buy = (! empty($conf->global->COMPTA_SERVICE_BUY_ACCOUNT) ? $conf->global->COMPTA_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef"));
+			} else {
+				$objp->code_buy = (! empty($conf->global->COMPTA_PRODUCT_BUY_ACCOUNT) ? $conf->global->COMPTA_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef"));					
+			}
+		}else {
+			$code_buy_notset = 'color:blue';
+		}
+		
 		print "<tr $bc[$var]>";
 
 		// Ref facture
@@ -191,7 +224,7 @@ if ($result) {
 		print price($objp->price);
 		print '</td>';
 
-		print '<td align="right">';
+		print '<td align="center" style="' . $code_buy_notset . '">';
 		print $objp->code_buy;
 		print '</td>';
 
@@ -216,4 +249,4 @@ if ($result) {
 }
 
 llxFooter();
-$db->close();
+$db->close();
\ No newline at end of file
-- 
GitLab