Laurent Destailleur 8 anni fa
parent
commit
0cfb0ff7b7

+ 16 - 3
htdocs/accountancy/index.php

@@ -43,7 +43,8 @@ $langs->load("admin");
 $langs->load("dict");
 $langs->load("bills");
 $langs->load("accountancy");
-
+$langs->load("compta");
+$langs->load("banks");
 
 /*
  * Actions
@@ -78,13 +79,22 @@ print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescProd", $step,
 print "<br>\n";
 print "<br>\n";
 $step++;
+//$textlink='<strong>'.$langs->transnoentitiesnoconv("Home").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("Modules")."-".$langs->transnoentitiesnoconv("Accountancy").'</strong>';
+$textlink='<strong>'.$langs->transnoentitiesnoconv("Home").'-'.$langs->transnoentitiesnoconv("MenuBankCash").'</strong>';
+print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescBank", $step, $textlink);
+print "<br>\n";
+print "<br>\n";
+$step++;
 print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescVat", $step, '<strong>'.$langs->transnoentitiesnoconv("Home").'-'.$langs->transnoentitiesnoconv("Setup").'-'.$langs->transnoentitiesnoconv("Dictionaries")."-".$langs->transnoentitiesnoconv("DictionaryVAT").'</strong>');
 print "<br>\n";
 print "<br>\n";
 if (! empty($conf->tax->enabled))
 {
+    $textlink = '<strong>'.$langs->transnoentitiesnoconv("Home").'-'.$langs->transnoentitiesnoconv("Setup").'-'.$langs->transnoentitiesnoconv("Dictionaries")."-".$langs->transnoentitiesnoconv("DictionarySocialContributions").'</strong>';
+    $textlink.= ' '.$langs->trans("and").' ';
+    $textlink.= '<strong>'.$langs->transnoentitiesnoconv("Home").'-'.$langs->transnoentitiesnoconv("Setup").'-'.$langs->transnoentitiesnoconv("Modules")."-".$langs->transnoentitiesnoconv("Accountancy").'</strong>';
     $step++;
-    print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescContrib", $step, '<strong>'.$langs->transnoentitiesnoconv("Home").'-'.$langs->transnoentitiesnoconv("Setup").'-'.$langs->transnoentitiesnoconv("Dictionaries")."-".$langs->transnoentitiesnoconv("DictionarySocialContributions").'</strong>');
+    print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescContrib", $step, $textlink);
     print "<br>\n";
     print "<br>\n";
 }
@@ -103,7 +113,7 @@ if (! empty($conf->don->enabled))
     print "<br>\n";
     print "<br>\n";
 }
-
+// Other: bank transfer, bank accounts
 
 print "<br>\n";
 print_fiche_titre($langs->trans("AccountancyAreaDescActionFreq"), '', 'object_calendarweek');
@@ -117,6 +127,9 @@ print "<br>\n";
 $step++;
 print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescSupplier", $step, '<strong>'.$langs->transnoentitiesnoconv("Financial").'-'.$langs->transnoentitiesnoconv("Accountancy")."-".$langs->transnoentitiesnoconv("SuppliersVentilation").'</strong>')."<br>\n";
 print "<br>\n";
+$step++;
+print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescWriteRecords", $step, '<strong>'.$langs->transnoentitiesnoconv("Financial").'-'.$langs->transnoentitiesnoconv("Accountancy")."-".$langs->transnoentitiesnoconv("SuppliersVentilation").'</strong>')."<br>\n";
+print "<br>\n";
 
 
 

+ 109 - 100
htdocs/accountancy/journal/purchasesjournal.php

@@ -59,6 +59,7 @@ if ($user->societe_id > 0)
 
 $action = GETPOST('action');
 
+
 /*
  * Actions
  */
@@ -303,137 +304,141 @@ if ($action == 'writebookkeeping') {
 	{
 	    setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
 	}
+	
+	$action='';
 }
 
 /*
  * View
  */
 
+$form = new Form($db);
+
 $companystatic = new Fournisseur($db);
 
 // Export
 if ($action == 'export_csv') {
-		$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
-		$journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL;
-
-		include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
-
-		// Model Cegid Expert Export
-		if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) {
-			$sep = ";";
-
-			foreach ( $tabfac as $key => $val ) {
-				$date = dol_print_date($val["date"], '%d%m%Y');
-
-				// Product / Service
-				foreach ( $tabht[$key] as $k => $mt ) {
-					$companystatic->id = $tabcompany[$key]['id'];
-					$companystatic->name = $tabcompany[$key]['name'];
-					$companystatic->client = $tabcompany[$key]['code_client'];
-
-					if ($mt) {
-						print $date . $sep;
-						print $purchase_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 dol_trunc($val["description"], 32) . $sep;
-						print $val["ref"];
-						print "\n";
-					}
-				}
+	$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
+	$journal = $conf->global->ACCOUNTING_PURCHASE_JOURNAL;
 
-				// VAT
-				foreach ( $tabtva[$key] as $k => $mt ) {
-					if ($mt) {
-						print $date . $sep;
-						print $purchase_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 $langs->trans("VAT") . $sep;
-						print $val["ref"];
-						print "\n";
-					}
+	include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
+
+	// Model Cegid Expert Export
+	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) {
+		$sep = ";";
+
+		foreach ( $tabfac as $key => $val ) {
+			$date = dol_print_date($val["date"], '%d%m%Y');
+
+			// Product / Service
+			foreach ( $tabht[$key] as $k => $mt ) {
+				$companystatic->id = $tabcompany[$key]['id'];
+				$companystatic->name = $tabcompany[$key]['name'];
+				$companystatic->client = $tabcompany[$key]['code_client'];
+
+				if ($mt) {
+					print $date . $sep;
+					print $purchase_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 dol_trunc($val["description"], 32) . $sep;
+					print $val["ref"];
+					print "\n";
 				}
+			}
 
-				foreach ( $tabttc[$key] as $k => $mt ) {
+			// VAT
+			foreach ( $tabtva[$key] as $k => $mt ) {
+				if ($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 length_accountg(html_entity_decode($k)) . $sep;
+					print $sep;
+					print ($mt < 0 ? 'C' : 'D') . $sep;
 					print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
-					print $companystatic->name . $sep;
+					print $langs->trans("VAT") . $sep;
 					print $val["ref"];
 					print "\n";
 				}
 			}
-		} elseif ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) {
-			// Model Classic Export
-			foreach ( $tabfac as $key => $val ) {
 
-				$invoicestatic->id = $key;
-				$invoicestatic->ref = $val["ref"];
-				$invoicestatic->ref = $val["refsologest"];
-				$invoicestatic->refsupplier = $val["refsuppliersologest"];
-				$invoicestatic->type = $val["type"];
-				$invoicestatic->description = html_entity_decode(dol_trunc($val["description"], 32));
+			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 $companystatic->name . $sep;
+				print $val["ref"];
+				print "\n";
+			}
+		}
+	} elseif ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) {
+		// Model Classic Export
+		foreach ( $tabfac as $key => $val ) {
 
-				$date = dol_print_date($val["date"], 'day');
+			$invoicestatic->id = $key;
+			$invoicestatic->ref = $val["ref"];
+			$invoicestatic->ref = $val["refsologest"];
+			$invoicestatic->refsupplier = $val["refsuppliersologest"];
+			$invoicestatic->type = $val["type"];
+			$invoicestatic->description = html_entity_decode(dol_trunc($val["description"], 32));
 
-				$companystatic->id = $tabcompany[$key]['id'];
-				$companystatic->name = $tabcompany[$key]['name'];
-				$companystatic->client = $tabcompany[$key]['code_client'];
+			$date = dol_print_date($val["date"], 'day');
 
-				// 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($companystatic->name, 16) . ' - ' . $val["refsuppliersologest"] . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
-						// print '"' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
-						print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
-						print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
-						print "\n";
-					}
-				}
-				// VAT
-				foreach ( $tabtva[$key] as $k => $mt ) {
-					if ($mt) {
-						print '"' . $date . '"' . $sep;
-						print '"' . $val["ref"] . '"' . $sep;
-						print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
-						// print '"' . $langs->trans("VAT") . '"' . $sep;
-						print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("VAT") . '"' . $sep;
-						print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
-						print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
-						print "\n";
-					}
-				}
+			$companystatic->id = $tabcompany[$key]['id'];
+			$companystatic->name = $tabcompany[$key]['name'];
+			$companystatic->client = $tabcompany[$key]['code_client'];
 
-				// Third party
-				foreach ( $tabttc[$key] as $k => $mt ) {
+			// 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_accounta(html_entity_decode($k)) . '"' . $sep;
-					print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("Code_tiers") . '"' . $sep;
-					print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
-					print '"' . ($mt >= 0 ? price($mt) : '') . '"';
+					print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
+					print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $val["refsuppliersologest"] . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
+					// print '"' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
+					print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
+					print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
+					print "\n";
 				}
-				print "\n";
 			}
+			// VAT
+			foreach ( $tabtva[$key] as $k => $mt ) {
+				if ($mt) {
+					print '"' . $date . '"' . $sep;
+					print '"' . $val["ref"] . '"' . $sep;
+					print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
+					// print '"' . $langs->trans("VAT") . '"' . $sep;
+					print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("VAT") . '"' . $sep;
+					print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
+					print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
+					print "\n";
+				}
+			}
+
+			// Third party
+			foreach ( $tabttc[$key] as $k => $mt ) {
+				print '"' . $date . '"' . $sep;
+				print '"' . $val["ref"] . '"' . $sep;
+				print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
+				print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("Code_tiers") . '"' . $sep;
+				print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
+				print '"' . ($mt >= 0 ? price($mt) : '') . '"';
+			}
+			print "\n";
 		}
-} else {
+	}
+}
 
-	llxHeader('', $langs->trans("PurchasesJournal"));
+if (empty($action) || $action == 'view') {
 
-	$form = new Form($db);
+	llxHeader('', $langs->trans("PurchasesJournal"));
 
 	$nom = $langs->trans("PurchasesJournal");
 	$nomlink = '';
@@ -484,6 +489,7 @@ if ($action == 'export_csv') {
 	print "<table class=\"noborder\" width=\"100%\">";
 	print "<tr class=\"liste_titre\">";
 	// /print "<td>".$langs->trans("JournalNum")."</td>";
+	print "<td></td>";
 	print "<td>" . $langs->trans("Date") . "</td>";
 	print "<td>" . $langs->trans("Piece") . ' (' . $langs->trans("InvoiceRef") . ")</td>";
 	print "<td>" . $langs->trans("AccountAccounting") . "</td>";
@@ -514,6 +520,7 @@ if ($action == 'export_csv') {
 
 			if ($mt) {
 				print "<tr " . $bc[$var] . " >";
+				print "<td></td>";
 				print "<td>" . $date . "</td>";
 				print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
 				print "<td>" . length_accountg($k) . "</td>";
@@ -530,6 +537,7 @@ if ($action == 'export_csv') {
 		foreach ( $tabtva[$key] as $k => $mt ) {
 			if ($mt) {
 				print "<tr " . $bc[$var] . " >";
+				print "<td></td>";
 				print "<td>" . $date . "</td>";
 				print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
 				print "<td>" . length_accountg($k) . "</td>";
@@ -543,7 +551,8 @@ if ($action == 'export_csv') {
 
 		// Third party
 		foreach ( $tabttc[$key] as $k => $mt ) {
-			print "<td>" . $date . "</td>";
+			print "<td></td>";
+		    print "<td>" . $date . "</td>";
 			print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
 			$companystatic->id = $tabcompany[$key]['id'];
 			$companystatic->name = $tabcompany[$key]['name'];

+ 341 - 331
htdocs/accountancy/journal/sellsjournal.php

@@ -62,16 +62,17 @@ if ($user->societe_id > 0)
 
 $action = GETPOST('action');
 
+
 /*
- * View
+ * Actions
  */
 
 $year_current = strftime("%Y", dol_now());
 $pastmonth = strftime("%m", dol_now()) - 1;
 $pastmonthyear = $year_current;
 if ($pastmonth == 0) {
-	$pastmonth = 12;
-	$pastmonthyear --;
+    $pastmonth = 12;
+    $pastmonthyear --;
 }
 
 $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear);
@@ -79,8 +80,8 @@ $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear);
 
 if (empty($date_start) || empty($date_end)) // We define date_start and date_end
 {
-	$date_start = dol_get_first_day($pastmonthyear, $pastmonth, false);
-	$date_end = dol_get_last_day($pastmonthyear, $pastmonth, false);
+    $date_start = dol_get_first_day($pastmonthyear, $pastmonth, false);
+    $date_end = dol_get_last_day($pastmonthyear, $pastmonth, false);
 }
 
 $p = explode(":", $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
@@ -99,358 +100,363 @@ $sql .= " JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc";
 $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 IN (" . getEntity("facture", 1) . ")";
+    $sql .= " AND f.entity IN (" . getEntity("facture", 1) . ")";
 }
 $sql .= " AND f.fk_statut > 0";
 if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
-	$sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")";
+    $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")";
 } else {
-	$sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_STANDARD . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")";
+    $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_STANDARD . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")";
 }
 $sql .= " AND fd.product_type IN (0,1)";
 if ($date_start && $date_end)
-	$sql .= " AND f.datef >= '" . $db->idate($date_start) . "' AND f.datef <= '" . $db->idate($date_end) . "'";
+    $sql .= " AND f.datef >= '" . $db->idate($date_start) . "' AND f.datef <= '" . $db->idate($date_end) . "'";
 $sql .= " ORDER BY f.datef";
 
 dol_syslog('accountancy/journal/sellsjournal.php', LOG_DEBUG);
 $result = $db->query($sql);
 if ($result) {
-	$tabfac = array ();
-	$tabht = array ();
-	$tabtva = array ();
-	$def_tva = array ();
-	$tabttc = array ();
-	$tabcompany = array ();
-
-	$num = $db->num_rows($result);
-	$i = 0;
-
-	while ( $i < $num ) {
-		$obj = $db->fetch_object($result);
-		// les variables
-		$cptcli = (! empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER)) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans("CodeNotDef");
-		$compta_soc = (! empty($obj->code_compta)) ? $obj->code_compta : $cptcli;
-
-		$compta_prod = $obj->compte;
-		if (empty($compta_prod)) {
-			if ($obj->product_type == 0)
-				$compta_prod = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef");
-			else
-				$compta_prod = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef");
-		}
-		$cpttva = (! empty($conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT : $langs->trans("CodeNotDef");
-		$compta_tva = (! empty($obj->account_tva) ? $obj->account_tva : $cpttva);
-
-
-		//Define array for display vat tx
-		$def_tva[$obj->rowid]=price($obj->tva_tx);
-
-		// Situation invoices handling
-		$line = new FactureLigne($db);
-		$line->fetch($obj->fdid);
-		$prev_progress = $line->get_prev_progress($obj->fdid);
-		if ($obj->type == Facture::TYPE_SITUATION) {
-			// Avoid divide by 0
-			if ($obj->situation_percent == 0) {
-				$situation_ratio = 0;
-			} else {
-				$situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
-			}
-		} else {
-			$situation_ratio = 1;
-		}
-
-		// Invoice lines
-		$tabfac[$obj->rowid]["date"] = $db->jdate($obj->df);
-		$tabfac[$obj->rowid]["ref"] = $obj->facnumber;
-		$tabfac[$obj->rowid]["type"] = $obj->type;
-		$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;
-		if (! isset($tabht[$obj->rowid][$compta_prod]))
-			$tabht[$obj->rowid][$compta_prod] = 0;
-		if (! isset($tabtva[$obj->rowid][$compta_tva]))
-			$tabtva[$obj->rowid][$compta_tva] = 0;
-		$tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio;
-		$tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
-		$tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
-		$tabcompany[$obj->rowid] = array (
-				'id' => $obj->socid,
-				'name' => $obj->name,
-				'code_client' => $obj->code_compta
-		);
-
-		$i ++;
-	}
+    $tabfac = array ();
+    $tabht = array ();
+    $tabtva = array ();
+    $def_tva = array ();
+    $tabttc = array ();
+    $tabcompany = array ();
+
+    $num = $db->num_rows($result);
+    $i = 0;
+
+    while ( $i < $num ) {
+        $obj = $db->fetch_object($result);
+        // les variables
+        $cptcli = (! empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER)) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans("CodeNotDef");
+        $compta_soc = (! empty($obj->code_compta)) ? $obj->code_compta : $cptcli;
+
+        $compta_prod = $obj->compte;
+        if (empty($compta_prod)) {
+            if ($obj->product_type == 0)
+                $compta_prod = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef");
+                else
+                    $compta_prod = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef");
+        }
+        $cpttva = (! empty($conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT : $langs->trans("CodeNotDef");
+        $compta_tva = (! empty($obj->account_tva) ? $obj->account_tva : $cpttva);
+
+
+        //Define array for display vat tx
+        $def_tva[$obj->rowid]=price($obj->tva_tx);
+
+        // Situation invoices handling
+        $line = new FactureLigne($db);
+        $line->fetch($obj->fdid);
+        $prev_progress = $line->get_prev_progress($obj->fdid);
+        if ($obj->type == Facture::TYPE_SITUATION) {
+            // Avoid divide by 0
+            if ($obj->situation_percent == 0) {
+                $situation_ratio = 0;
+            } else {
+                $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
+            }
+        } else {
+            $situation_ratio = 1;
+        }
+
+        // Invoice lines
+        $tabfac[$obj->rowid]["date"] = $db->jdate($obj->df);
+        $tabfac[$obj->rowid]["ref"] = $obj->facnumber;
+        $tabfac[$obj->rowid]["type"] = $obj->type;
+        $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;
+            if (! isset($tabht[$obj->rowid][$compta_prod]))
+                $tabht[$obj->rowid][$compta_prod] = 0;
+                if (! isset($tabtva[$obj->rowid][$compta_tva]))
+                    $tabtva[$obj->rowid][$compta_tva] = 0;
+                    $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio;
+                    $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio;
+                    $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio;
+                    $tabcompany[$obj->rowid] = array (
+                        'id' => $obj->socid,
+                        'name' => $obj->name,
+                        'code_client' => $obj->code_compta
+                    );
+
+                    $i ++;
+    }
 } else {
-	dol_print_error($db);
+    dol_print_error($db);
 }
 
-/*
- * Action
- * FIXME Action must be set before any view part to respect MVC
- */
-
 // Bookkeeping Write
 if ($action == 'writebookkeeping') {
-	$now = dol_now();
-	$error = 0;
-
-	foreach ( $tabfac as $key => $val ) {
-	    
-	    $errorforline = 0;
-	     
-	    $db->begin();
-	     
-		$companystatic = new Societe($db);
-		$invoicestatic = new Facture($db);
-
-		$companystatic->id = $tabcompany[$key]['id'];
-		$companystatic->name = $tabcompany[$key]['name'];
-		$companystatic->client = $tabcompany[$key]['code_client'];
-
-		$invoicestatic->id = $key;
-		$invoicestatic->ref = (string) $val["ref"];
-
-		foreach ( $tabttc[$key] as $k => $mt ) {
-			$bookkeeping = new BookKeeping($db);
-			$bookkeeping->doc_date = $val["date"];
-			$bookkeeping->doc_ref = $val["ref"];
-			$bookkeeping->date_create = $now;
-			$bookkeeping->doc_type = 'customer_invoice';
-			$bookkeeping->fk_doc = $key;
-			$bookkeeping->fk_docdet = $val["fk_facturedet"];
-			$bookkeeping->code_tiers = $tabcompany[$key]['code_client'];
-			$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
-			// $bookkeeping->label_compte = $tabcompany[$key]['name'];
-			$bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers");
-			$bookkeeping->montant = $mt;
-			$bookkeeping->sens = ($mt >= 0) ? 'D' : 'C';
-			$bookkeeping->debit = ($mt >= 0) ? $mt : 0;
-			$bookkeeping->credit = ($mt < 0) ? $mt : 0;
-			$bookkeeping->code_journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
-			$bookkeeping->fk_user_author = $user->id;
-
-			$result = $bookkeeping->create($user);
-			if ($result < 0) {
-				$error++;
-				$errorforline++;
-				setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
-			}
-		}
+    $now = dol_now();
+    $error = 0;
+
+    foreach ( $tabfac as $key => $val ) {
+         
+        $errorforline = 0;
+
+        $db->begin();
+
+        $companystatic = new Societe($db);
+        $invoicestatic = new Facture($db);
+
+        $companystatic->id = $tabcompany[$key]['id'];
+        $companystatic->name = $tabcompany[$key]['name'];
+        $companystatic->client = $tabcompany[$key]['code_client'];
+
+        $invoicestatic->id = $key;
+        $invoicestatic->ref = (string) $val["ref"];
+
+        foreach ( $tabttc[$key] as $k => $mt ) {
+            $bookkeeping = new BookKeeping($db);
+            $bookkeeping->doc_date = $val["date"];
+            $bookkeeping->doc_ref = $val["ref"];
+            $bookkeeping->date_create = $now;
+            $bookkeeping->doc_type = 'customer_invoice';
+            $bookkeeping->fk_doc = $key;
+            $bookkeeping->fk_docdet = $val["fk_facturedet"];
+            $bookkeeping->code_tiers = $tabcompany[$key]['code_client'];
+            $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER;
+            // $bookkeeping->label_compte = $tabcompany[$key]['name'];
+            $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers");
+            $bookkeeping->montant = $mt;
+            $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C';
+            $bookkeeping->debit = ($mt >= 0) ? $mt : 0;
+            $bookkeeping->credit = ($mt < 0) ? $mt : 0;
+            $bookkeeping->code_journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
+            $bookkeeping->fk_user_author = $user->id;
+
+            $result = $bookkeeping->create($user);
+            if ($result < 0) {
+                $error++;
+                $errorforline++;
+                setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
+            }
+        }
+
+        // Product / Service
+        foreach ( $tabht[$key] as $k => $mt ) {
+            if ($mt) {
+                // get compte id and label
+                $accountingaccount = new AccountingAccount($db);
+                if ($accountingaccount->fetch(null, $k)) {
+                    $bookkeeping = new BookKeeping($db);
+                    $bookkeeping->doc_date = $val["date"];
+                    $bookkeeping->doc_ref = $val["ref"];
+                    $bookkeeping->date_create = $now;
+                    $bookkeeping->doc_type = 'customer_invoice';
+                    $bookkeeping->fk_doc = $key;
+                    $bookkeeping->fk_docdet = $val["fk_facturedet"];
+                    $bookkeeping->code_tiers = '';
+                    $bookkeeping->numero_compte = $k;
+                    $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount->label;
+                    $bookkeeping->montant = $mt;
+                    $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
+                    $bookkeeping->debit = ($mt < 0) ? $mt : 0;
+                    $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
+                    $bookkeeping->code_journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
+                    $bookkeeping->fk_user_author = $user->id;
+
+                    $result = $bookkeeping->create($user);
+                    if ($result < 0) {
+                        $error++;
+                        $errorforline++;
+                        setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
+                    }
+                }
+            }
+        }
+
+        // VAT
+        // var_dump($tabtva);
+        foreach ( $tabtva[$key] as $k => $mt ) {
+            if ($mt) {
+                $bookkeeping = new BookKeeping($db);
+                $bookkeeping->doc_date = $val["date"];
+                $bookkeeping->doc_ref = $val["ref"];
+                $bookkeeping->date_create = $now;
+                $bookkeeping->doc_type = 'customer_invoice';
+                $bookkeeping->fk_doc = $key;
+                $bookkeeping->fk_docdet = $val["fk_facturedet"];
+                $bookkeeping->code_tiers = '';
+                $bookkeeping->numero_compte = $k;
+                $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT").' '.$def_tva[$key];
+                $bookkeeping->montant = $mt;
+                $bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
+                $bookkeeping->debit = ($mt < 0) ? $mt : 0;
+                $bookkeeping->credit = ($mt >= 0) ? $mt : 0;
+                $bookkeeping->code_journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
+                $bookkeeping->fk_user_author = $user->id;
+
+                $result = $bookkeeping->create($user);
+                if ($result < 0) {
+                    $error++;
+                    $errorforline++;
+                    setEventMessages($object->error, $object->errors, 'errors');
+                }
+            }
+        }
+
+
+        if (! $errorforline)
+        {
+            $db->commit();
+        }
+        else
+        {
+            $db->rollback();
+        }
+
+    }
+
+    if (empty($error)) {
+        setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
+    }
+    elseif (count($tabpay) == $error)
+    {
+        setEventMessages($langs->trans("NoRecordSaved"), null, 'warnings');
+    }
+    else
+    {
+        setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
+    }
+    
+    $action='';
+}
 
-		// Product / Service
-		foreach ( $tabht[$key] as $k => $mt ) {
-			if ($mt) {
-				// get compte id and label
-				$accountingaccount = new AccountingAccount($db);
-				if ($accountingaccount->fetch(null, $k)) {
-					$bookkeeping = new BookKeeping($db);
-					$bookkeeping->doc_date = $val["date"];
-					$bookkeeping->doc_ref = $val["ref"];
-					$bookkeeping->date_create = $now;
-					$bookkeeping->doc_type = 'customer_invoice';
-					$bookkeeping->fk_doc = $key;
-					$bookkeeping->fk_docdet = $val["fk_facturedet"];
-					$bookkeeping->code_tiers = '';
-					$bookkeeping->numero_compte = $k;
-					$bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount->label;
-					$bookkeeping->montant = $mt;
-					$bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
-					$bookkeeping->debit = ($mt < 0) ? $mt : 0;
-					$bookkeeping->credit = ($mt >= 0) ? $mt : 0;
-					$bookkeeping->code_journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
-					$bookkeeping->fk_user_author = $user->id;
-
-					$result = $bookkeeping->create($user);
-					if ($result < 0) {
-						$error++;
-						$errorforline++;
-						setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
-					}
-				}
-			}
-		}
 
-		// VAT
-		// var_dump($tabtva);
-		foreach ( $tabtva[$key] as $k => $mt ) {
-			if ($mt) {
-				$bookkeeping = new BookKeeping($db);
-				$bookkeeping->doc_date = $val["date"];
-				$bookkeeping->doc_ref = $val["ref"];
-				$bookkeeping->date_create = $now;
-				$bookkeeping->doc_type = 'customer_invoice';
-				$bookkeeping->fk_doc = $key;
-				$bookkeeping->fk_docdet = $val["fk_facturedet"];
-				$bookkeeping->code_tiers = '';
-				$bookkeeping->numero_compte = $k;
-				$bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT").' '.$def_tva[$key];
-				$bookkeeping->montant = $mt;
-				$bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
-				$bookkeeping->debit = ($mt < 0) ? $mt : 0;
-				$bookkeeping->credit = ($mt >= 0) ? $mt : 0;
-				$bookkeeping->code_journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
-				$bookkeeping->fk_user_author = $user->id;
-
-				$result = $bookkeeping->create($user);
-				if ($result < 0) {
-					$error++;
-					$errorforline++;
-					setEventMessages($object->error, $object->errors, 'errors');
-				}
-			}
-		}
-		
 
-		if (! $errorforline)
-		{
-		    $db->commit();
-		}
-		else
-		{
-		    $db->rollback();
-		}
-		
-	}
+/*
+ * View
+ */
 
-	if (empty($error)) {
-	    setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs');
-	}
-	elseif (count($tabpay) == $error)
-	{
-	    setEventMessages($langs->trans("NoRecordSaved"), null, 'warnings');
-	}
-	else
-	{
-	    setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings');
-	}
-}
+$form = new Form($db);
 
 // Export
 if ($action == 'export_csv') {
 
-	$sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
-	$sell_journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
-
-	include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
-
-	$companystatic = new Client($db);
-
-	// Model Cegid Expert Export
-	if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) {
-		$sep = ";";
-
-		foreach ( $tabfac as $key => $val ) {
-			$companystatic->id = $tabcompany[$key]['id'];
-			$companystatic->name = $tabcompany[$key]['name'];
-			$companystatic->client = $tabcompany[$key]['code_client'];
-
-			$invoicestatic->id = $key;
-			$invoicestatic->ref = $val["ref"];
-
-			$date = dol_print_date($val["date"], '%d%m%Y');
-
-			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 dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . $sep;
-				print $val["ref"];
-				print "\n";
-			}
-
-			// Product / Service
-			foreach ( $tabht[$key] as $k => $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($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount_static->label . $sep;
-					print $val["ref"];
-					print "\n";
-				}
-			}
-
-			// TVA
-			foreach ( $tabtva[$key] as $k => $mt ) {
-				if ($mt) {
-					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($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . $sep;
-					// print $langs->trans("VAT") . $sep;
-					print $val["ref"];
-					print "\n";
-				}
-			}
-		}
-	} elseif ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) {
-		// Model Classic Export
-		foreach ( $tabfac as $key => $val ) {
-			$companystatic->id = $tabcompany[$key]['id'];
-			$companystatic->name = $tabcompany[$key]['name'];
-			$companystatic->client = $tabcompany[$key]['code_client'];
-
-			$invoicestatic->id = $key;
-			$invoicestatic->ref = $val["ref"];
-
-			$date = dol_print_date($val["date"], 'day');
-
-			foreach ( $tabttc[$key] as $k => $mt ) {
-				print '"' . $date . '"' . $sep;
-				print '"' . $val["ref"] . '"' . $sep;
-				print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
-				print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . '"' . $sep;
-				print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
-				print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
-				print "\n";
-			}
-
-			// 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($companystatic->name, 16) . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
-					print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
-					print '"' . ($mt >= 0 ? price($mt) : '') . '"';
-					print "\n";
-				}
-			}
-
-			// VAT
-			foreach ( $tabtva[$key] as $k => $mt ) {
-				if ($mt) {
-					print '"' . $date . '"' . $sep;
-					print '"' . $val["ref"] . '"' . $sep;
-					print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
-					print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . '"' . $sep;
-					print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
-					print '"' . ($mt >= 0 ? price($mt) : '') . '"';
-					print "\n";
-				}
-			}
-		}
-	}
-} else {
+    $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV;
+    $sell_journal = $conf->global->ACCOUNTING_SELL_JOURNAL;
+
+    include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php';
+
+    $companystatic = new Client($db);
+
+    // Model Cegid Expert Export
+    if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) {
+        $sep = ";";
+
+        foreach ( $tabfac as $key => $val ) {
+            $companystatic->id = $tabcompany[$key]['id'];
+            $companystatic->name = $tabcompany[$key]['name'];
+            $companystatic->client = $tabcompany[$key]['code_client'];
+
+            $invoicestatic->id = $key;
+            $invoicestatic->ref = $val["ref"];
+
+            $date = dol_print_date($val["date"], '%d%m%Y');
+
+            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 dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . $sep;
+                print $val["ref"];
+                print "\n";
+            }
+
+            // Product / Service
+            foreach ( $tabht[$key] as $k => $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($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount_static->label . $sep;
+                    print $val["ref"];
+                    print "\n";
+                }
+            }
+
+            // TVA
+            foreach ( $tabtva[$key] as $k => $mt ) {
+                if ($mt) {
+                    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($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . $sep;
+                    // print $langs->trans("VAT") . $sep;
+                    print $val["ref"];
+                    print "\n";
+                }
+            }
+        }
+    } elseif ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) {
+        // Model Classic Export
+        foreach ( $tabfac as $key => $val ) {
+            $companystatic->id = $tabcompany[$key]['id'];
+            $companystatic->name = $tabcompany[$key]['name'];
+            $companystatic->client = $tabcompany[$key]['code_client'];
+
+            $invoicestatic->id = $key;
+            $invoicestatic->ref = $val["ref"];
+
+            $date = dol_print_date($val["date"], 'day');
+
+            foreach ( $tabttc[$key] as $k => $mt ) {
+                print '"' . $date . '"' . $sep;
+                print '"' . $val["ref"] . '"' . $sep;
+                print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
+                print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . '"' . $sep;
+                print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
+                print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
+                print "\n";
+            }
+
+            // 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($companystatic->name, 16) . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep;
+                    print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
+                    print '"' . ($mt >= 0 ? price($mt) : '') . '"';
+                    print "\n";
+                }
+            }
+
+            // VAT
+            foreach ( $tabtva[$key] as $k => $mt ) {
+                if ($mt) {
+                    print '"' . $date . '"' . $sep;
+                    print '"' . $val["ref"] . '"' . $sep;
+                    print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
+                    print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . '"' . $sep;
+                    print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
+                    print '"' . ($mt >= 0 ? price($mt) : '') . '"';
+                    print "\n";
+                }
+            }
+        }
+    }
+}
 
-	$form = new Form($db);
+if (empty($action) || $action == 'view') {
 
 	llxHeader('', $langs->trans("SellsJournal"));
 
@@ -500,6 +506,7 @@ if ($action == 'export_csv') {
 	$i = 0;
 	print "<table class=\"noborder\" width=\"100%\">";
 	print "<tr class=\"liste_titre\">";
+	print "<td></td>";
 	print "<td>" . $langs->trans("Date") . "</td>";
 	print "<td>" . $langs->trans("Piece") . ' (' . $langs->trans("InvoiceRef") . ")</td>";
 	print "<td>" . $langs->trans("AccountAccounting") . "</td>";
@@ -524,6 +531,7 @@ if ($action == 'export_csv') {
 		// Third party
 		foreach ( $tabttc[$key] as $k => $mt ) {
 			print "<tr " . $bc[$var] . ">";
+			print "<td><!-- Thirdparty --></td>";
 			print "<td>" . $date . "</td>";
 			print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
 			$companystatic->id = $tabcompany[$key]['id'];
@@ -545,6 +553,7 @@ if ($action == 'export_csv') {
 
 			if ($mt) {
 				print "<tr " . $bc[$var] . ">";
+				print "<td><!-- Product --></td>";
 				print "<td>" . $date . "</td>";
 				print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
 				print "<td>" . length_accountg($k) . "</td>";
@@ -560,6 +569,7 @@ if ($action == 'export_csv') {
 		foreach ( $tabtva[$key] as $k => $mt ) {
 			if ($mt) {
 				print "<tr " . $bc[$var] . ">";
+				print "<td><!-- VAT --></td>";
 				print "<td>" . $date . "</td>";
 				print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
 				print "<td>" . length_accountg($k) . "</td>";

+ 3 - 2
htdocs/core/lib/accounting.lib.php

@@ -105,7 +105,7 @@ function clean_account($account)
 }
 
 /**
- * Return general accounting account with defined length
+ * Return General accounting account with defined length
  *
  * @param 	string	$account		General accounting account
  * @return	string          		String with defined length
@@ -137,7 +137,8 @@ function length_accountg($account)
 }
 
 /**
- * Return auxiliary accounting account with defined length
+ * Return Auxiliary accounting account with defined length
+ * TODO For thirdparty accounts only, or products too ?
  *
  * @param 	string	$accounta		Auxiliary accounting account
  * @return	string          		String with defined length

+ 5 - 2
htdocs/langs/en_US/accountancy.lang

@@ -19,7 +19,8 @@ AccountancyAreaDescIntro=Usage of the accountancy module is done in several step
 AccountancyAreaDescActionOnce=The following action are usually executed one time only, or once per year...
 AccountancyAreaDescActionFreq=The following action are usually executed every month, week or day for very large companies...
 AccountancyAreaDescChart=STEP %s: Create or check your chart of account from menu %s
-AccountancyAreaDescProd=STEP %s: Check the binding between products/services and accounting account is done. Complete missing bindings. This will save you time in future for the next steps by suggesting you the correct default accounting account on your invoice lines.<br>For this you can use the menu entry %s.    
+AccountancyAreaDescProd=STEP %s: Check the binding between products/services and accounting account is done. Complete missing bindings. This will save you time in future for the next steps by suggesting you the correct default accounting account on your invoice lines.<br>For this you can use the menu entry %s.
+AccountancyAreaDescBank=STEP %s: Check the binding between bank accounts and accounting account is done. Complete missing bindings. This will save you time in future for the next steps by suggesting you the correct default accounting account on your payment lines.<br>For this, go on the card of each financial account. You can start from page %s.
 AccountancyAreaDescVat=STEP %s: Check the binding between vat payment and accounting account is done. Complete missing bindings. This will save you time in future for the next steps by suggesting you the correct default accounting account on records related to VAT payments.<br>You can set accounting accounts to use for each VAT from page %s.    
 AccountancyAreaDescSal=STEP %s: Check the binding between salaries payment and accounting account is done. Complete missing bindings. This will save you time in future for the next steps by suggesting you the correct default accounting account on records related to payment of salaries.<br>For this you can use the menu entry %s.    
 AccountancyAreaDescContrib=STEP %s: Check the binding between special expences (social or fiscal contributions) and accounting account is done. Complete missing bindings. This will save you time in future for the next steps by suggesting you the correct default accounting account on records related to payments of social contributions.<br>For this you can use the menu entry %s.    
@@ -27,6 +28,7 @@ AccountancyAreaDescDonation=STEP %s: Check the binding between donation and acco
     
 AccountancyAreaDescCustomer=STEP %s: Check the binding between existing customer invoice lines and accounting accounting is done. Complete missing bindings. Once binding is complete, application will be able to record transactions in General Ledger in one click.<br>For this you can use the menu entry %s.
 AccountancyAreaDescSupplier=STEP %s: Check the binding between existing supplier invoice lines and accounting accounting is done. Complete missing bindings. Once binding is complete, application will be able to record transactions in General Ledger in one click.<br>For this you can use the menu entry %s.
+AccountancyAreaDescWriteRecords=STEP %s: Write transactions into the General Ledger. Add or edit existing transactions and generate reports
 
 Selectchartofaccounts=Select a chart of accounts
 Addanaccount=Add an accounting account
@@ -195,7 +197,8 @@ ErrorNoAccountingCategoryForThisCountry=No accounting category are available for
 ExportNotSupported=The export format setuped is not supported into this page
 BookeppingLineAlreayExists=Lines already existing into bookeeping
 
-
 Binded=Lines binded
 ToBind=Lines to bind
 
+WarningReportNotReliable=Warning, this report is not based on the General Ledger, so is not reliable yet. It will be replaced be a correct report in a next version. 
+