浏览代码

Merge branch 'develop' into develop_advtargetemailiing

Conflicts:
	htdocs/admin/dict.php
	htdocs/core/class/html.formaccounting.class.php
	htdocs/install/mysql/migration/3.9.0-4.0.0.sql
	htdocs/install/mysql/tables/llx_c_accounting_category.sql
Florian HENRY 9 年之前
父节点
当前提交
344a87f970
共有 40 个文件被更改,包括 1011 次插入222 次删除
  1. 6 6
      htdocs/accountancy/admin/account.php
  2. 13 3
      htdocs/accountancy/admin/card.php
  3. 23 19
      htdocs/accountancy/bookkeeping/balance.php
  4. 43 1
      htdocs/accountancy/class/bookkeeping.class.php
  5. 21 7
      htdocs/accountancy/journal/purchasesjournal.php
  6. 38 21
      htdocs/accountancy/journal/sellsjournal.php
  7. 1 66
      htdocs/admin/bank.php
  8. 287 0
      htdocs/admin/chequereceipts.php
  9. 5 5
      htdocs/admin/dict.php
  10. 1 1
      htdocs/compta/facture/class/facture-rec.class.php
  11. 8 8
      htdocs/compta/paiement/cheque/card.php
  12. 115 47
      htdocs/compta/paiement/cheque/class/remisecheque.class.php
  13. 2 1
      htdocs/compta/paiement/cheque/index.php
  14. 4 3
      htdocs/compta/paiement/cheque/list.php
  15. 1 1
      htdocs/contrat/list.php
  16. 3 3
      htdocs/core/class/html.formaccounting.class.php
  17. 6 6
      htdocs/core/lib/accounting.lib.php
  18. 6 0
      htdocs/core/lib/bank.lib.php
  19. 5 5
      htdocs/core/lib/functions.lib.php
  20. 1 1
      htdocs/core/modules/cheque/doc/pdf_blochet.class.php
  21. 150 0
      htdocs/core/modules/cheque/mod_chequereceipt_mint.php
  22. 140 0
      htdocs/core/modules/cheque/mod_chequereceipt_thyme.php
  23. 83 1
      htdocs/core/modules/cheque/modules_chequereceipts.php
  24. 21 1
      htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php
  25. 1 1
      htdocs/core/search_page.php
  26. 1 1
      htdocs/install/mysql/migration/3.9.0-4.0.0.sql
  27. 1 1
      htdocs/install/mysql/tables/llx_accounting_account.sql
  28. 1 1
      htdocs/install/mysql/tables/llx_bordereau_cheque.key.sql
  29. 3 3
      htdocs/install/mysql/tables/llx_bordereau_cheque.sql
  30. 1 1
      htdocs/install/mysql/tables/llx_c_accounting_category.sql
  31. 2 0
      htdocs/langs/en_US/admin.lang
  32. 2 2
      htdocs/projet/class/task.class.php
  33. 1 1
      htdocs/projet/contact.php
  34. 1 1
      htdocs/projet/document.php
  35. 1 1
      htdocs/projet/element.php
  36. 1 1
      htdocs/projet/ganttview.php
  37. 1 1
      htdocs/projet/note.php
  38. 1 1
      htdocs/projet/tasks.php
  39. 7 0
      htdocs/projet/tasks/contact.php
  40. 3 0
      htdocs/theme/eldy/style.css.php

+ 6 - 6
htdocs/accountancy/admin/account.php

@@ -161,11 +161,11 @@ if ($result) {
 	print '</tr>';
 	
 	print '<tr class="liste_titre">';
-	print '<td class="liste_titre"><input type="text" class="flat" size="15" name="search_account" value="' . $search_account . '"></td>';
-	print '<td class="liste_titre"><input type="text" class="flat" size="15" name="search_label" value="' . $search_label . '"></td>';
-	print '<td class="liste_titre"><input type="text" class="flat" size="15" name="search_accountparent" value="' . $search_accountparent . '"></td>';
-	print '<td class="liste_titre"><input type="text" class="flat" size="15" name="search_pcgtype" value="' . $search_pcgtype . '"></td>';
-	print '<td class="liste_titre"><input type="text" class="flat" size="15" name="search_pcgsubtype" value="' . $search_pcgsubtype . '"></td>';
+	print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_account" value="' . $search_account . '"></td>';
+	print '<td class="liste_titre"><input type="text" class="flat" size="20" name="search_label" value="' . $search_label . '"></td>';
+	print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_accountparent" value="' . $search_accountparent . '"></td>';
+	print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_pcgtype" value="' . $search_pcgtype . '"></td>';
+	print '<td class="liste_titre"><input type="text" class="flat" size="6" name="search_pcgsubtype" value="' . $search_pcgsubtype . '"></td>';
 	print '<td class="liste_titre">&nbsp;</td>';
 	print '<td align="right" colspan="2" class="liste_titre">';
 	print '<input type="image" class="liste_titre" src="' . img_picto($langs->trans("Search"), 'search.png', '', '', 1) . '" name="button_search" value="' . dol_escape_htmltag($langs->trans("Search")) . '" title="' . dol_escape_htmltag($langs->trans("Search")) . '">';
@@ -190,7 +190,7 @@ if ($result) {
 		print '<td>' . $accountstatic->getNomUrl(1) . '</td>';
 		print '<td>' . $obj->label . '</td>';
 
-		if ($obj->account_parent)
+		if (! empty($obj->account_parent))
         {
 			$accountparent->id = $obj->rowid2;
 			$accountparent->label = $obj->label2;

+ 13 - 3
htdocs/accountancy/admin/card.php

@@ -59,12 +59,17 @@ if ($action == 'add') {
 
 		// Clean code
 		$account_number = clean_account(GETPOST('account_number')); // Accounting account without zero on the right
+		if (GETPOST('account_category') <= 0) {
+			$account_parent = '';
+		} else {
+			$account_parent = GETPOST('account_category','int');
+		}
 		
 		$object->fk_pcg_version = $obj->pcg_version;
 		$object->pcg_type = GETPOST('pcg_type');
 		$object->pcg_subtype = GETPOST('pcg_subtype');
 		$object->account_number = $account_number;
-		$object->account_parent = GETPOST('account_parent', 'int');
+		$object->account_parent = $account_parent;
 		$object->account_category = GETPOST('account_category');
 		$object->label = GETPOST('label', 'alpha');
 		$object->active = 1;
@@ -96,12 +101,17 @@ if ($action == 'add') {
 
 		// Clean code
 		$account_number = clean_account(GETPOST('account_number')); // Accounting account without zero on the right
-		
+		if (GETPOST('account_category') <= 0) {
+			$account_parent = '';
+		} else {
+			$account_parent = GETPOST('account_category','int');
+		}
+
 		$object->fk_pcg_version = $obj->pcg_version;
 		$object->pcg_type = GETPOST('pcg_type');
 		$object->pcg_subtype = GETPOST('pcg_subtype');
 		$object->account_number = $account_number;
-		$object->account_parent = GETPOST('account_parent', 'int');
+		$object->account_parent = $account_parent;
 		$object->account_category = GETPOST('account_category');
 		$object->label = GETPOST('label', 'alpha');
 		

+ 23 - 19
htdocs/accountancy/bookkeeping/balance.php

@@ -1,7 +1,7 @@
 <?php
-/* Copyright (C) 2013-2014 Olivier Geffroy		<jeff@jeffinfo.com>
- * Copyright (C) 2013-2016 Florian Henry		<florian.henry@open-concept.pro>
- * Copyright (C) 2013-2015 Alexandre Spangaro	<aspangaro.dolibarr@gmail.com>
+/* Copyright (C) 2016 		Olivier Geffroy		<jeff@jeffinfo.com>
+ * Copyright (C) 2016 		Florian Henry		<florian.henry@open-concept.pro>
+ * Copyright (C) 2016 		Alexandre Spangaro	<aspangaro.dolibarr@gmail.com>
  *
  * 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
@@ -19,9 +19,9 @@
  */
 
 /**
- * \file htdocs/accountancy/bookkeeping/balance.php
- * \ingroup Accounting Expert
- * \brief Balance of book keeping
+ *  \file 		htdocs/accountancy/bookkeeping/balance.php
+ *  \ingroup 	Advanced accountancy
+ *  \brief 		Balance of book keeping
  */
 require '../../main.inc.php';
 
@@ -137,7 +137,6 @@ else {
 	/*
 	 * List
 	 */
-
 	$nbtotalofrecords = 0;
 	if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
 		$nbtotalofrecords = $object->fetchAllBalance($sortorder, $sortfield, 0, 0, $filter);
@@ -150,13 +149,12 @@ else {
 	if ($result < 0) {
 		setEventMessages($object->error, $object->errors, 'errors');
 	}
-
-	print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield, $sortorder, '', $result, $nbtotalofrecords);
-
+	
+	print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield, $sortorder, '', $result);
+	
 	print '<form method="GET" id="searchFormList" action="' . $_SERVER["PHP_SELF"] . '">';
 	print '<div class="tabsAction">' . "\n";
 	print '<div class="inline-block divButAction"><input type="submit" name="button_export_csv" class="butAction" value="' . $langs->trans("Export") . '" /></div>';
-
 	print '</div>';
 
 	print '<div class="liste_titre">';
@@ -169,6 +167,7 @@ else {
 	print '<table class="noborder" width="100%">';
 	print '<tr class="liste_titre">';
 	print_liste_field_titre($langs->trans("Numerocompte"), $_SERVER['PHP_SELF'], "t.numero_compte", "", $options, "", $sortfield, $sortorder);
+	print_liste_field_titre($langs->trans("Labelcompte"), $_SERVER['PHP_SELF'], "t.label_compte", "", $options, "", $sortfield, $sortorder);
 	print_liste_field_titre($langs->trans("Debit"), $_SERVER['PHP_SELF'], "t.debit", "", $options, 'align="right"', $sortfield, $sortorder);
 	print_liste_field_titre($langs->trans("Credit"), $_SERVER['PHP_SELF'], "t.credit", "", $options, 'align="right"', $sortfield, $sortorder);
 	print_liste_field_titre($langs->trans("Solde"), $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder);
@@ -176,11 +175,11 @@ else {
 	print "</tr>\n";
 
 	print '<tr class="liste_titre">';
-	print '<td>';
+	print '<td colspan="2">';
 	print $langs->trans('From');
 	print $formventilation->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, '');
 	print '<br>';
-	print $langs->trans('To');
+	print $langs->trans('to');
 	print $formventilation->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array (), 1, 1, '');
 	print '</td>';
 
@@ -203,23 +202,28 @@ else {
 
 	foreach ( $object->lines as $line ) {
 		$var = ! $var;
-
+		$link = '';
 		$total_debit += $line->debit;
 		$total_credit += $line->credit;
-
+		$description = $object->get_compte_desc($line->numero_compte); // Search description of the account
+		if(empty($description)){
+			$link = '<a href="../admin/card.php?action=create&compte=' . length_accountg($line->numero_compte) . '">' . img_edit_add() .'</a>';
+		}
 		print "<tr $bc[$var]>";
 
 		print '<td>' . length_accountg($line->numero_compte) . '</td>';
-		print '<td align="right">' . price($line->debit) . '</td>';
-		print '<td align="right">' . price($line->credit) . '</td>';
-		print '<td align="right">' . price($line->credit - $line->debit) . '</td>';
-		print '<td align="center">';
+		print '<td>' . $description . '</td>';
+		print '<td align="right">' .  number_format($line->debit, 2, ',', ' ') . '</td>';
+        print '<td align="right">' . number_format($line->credit, 2, ',', ' ') . '</td>';
+        print '<td align="right">' . number_format($line->credit - $line->debit, 2, ',', ' ') . '</td>';
+		print '<td align="center">' . $link;
 		print '</td>';
 		print "</tr>\n";
 	}
 
 	print '<tr class="liste_total">';
 	print '<td></td>';
+	print '<td></td>';
 	print '<td  align="right">';
 	print price($total_debit);
 	print '</td>';

+ 43 - 1
htdocs/accountancy/class/bookkeeping.class.php

@@ -1,7 +1,7 @@
 <?php
 /* Copyright (C) 2007-2012  Laurent Destailleur <eldy@users.sourceforge.net>
  * Copyright (C) 2014       Juanjo Menent       <jmenent@2byte.es>
- * Copyright (C) 2015-2016 Florian Henry       <florian.henry@open-concept.pro>
+ * Copyright (C) 2015-2016  Florian Henry       <florian.henry@open-concept.pro>
  * Copyright (C) 2015       Raphaël Doursenaud  <rdoursenaud@gpcsolutions.fr>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -1207,6 +1207,48 @@ class BookKeeping extends CommonObject
 			return - 1;
 		}
 	}
+	
+	/**
+	* Description of accounting account
+	*
+	* @param 	string 	$account	Accounting account
+	* @return 	string 	
+	*/
+	function get_compte_desc($account = null)
+	{	
+		global $conf;
+		$pcgver = $conf->global->CHARTOFACCOUNTS;
+
+		$sql  = "SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category";
+		$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa ";
+		$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
+		$sql .= " AND aa.account_number = '" . $account . "'";
+		$sql .= " AND asy.rowid = " . $pcgver;
+		$sql .= " AND aa.active = 1";
+		$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid";
+
+		dol_syslog(get_class($this) . "::select_account sql=" . $sql, LOG_DEBUG);
+		$resql = $this->db->query($sql);
+		if ($resql) {
+			$obj = '';
+			if ($this->db->num_rows($resql)) {
+				$obj = $this->db->fetch_object($resql);	
+			}
+			
+			if(empty($obj->category)){				
+				return $obj->label;
+			}else{
+				return $obj->label.' ('.$obj->category.')';
+				
+			}
+		} else {
+			$this->error = "Error " . $this->db->lasterror();
+			dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR);
+
+			return -1;
+		}
+	}
+	
 }
 
 /**

+ 21 - 7
htdocs/accountancy/journal/purchasesjournal.php

@@ -4,7 +4,7 @@
  * Copyright (C) 2011		Juanjo Menent		<jmenent@2byte.es>
  * Copyright (C) 2012		Regis Houssin		<regis@dolibarr.fr>
  * Copyright (C) 2013-2015  Alexandre Spangaro	<aspangaro.dolibarr@gmail.com>
- * Copyright (C) 2013-2014  Olivier Geffroy		<jeff@jeffinfo.com>
+ * Copyright (C) 2013-2016  Olivier Geffroy		<jeff@jeffinfo.com>
  * Copyright (C) 2013-2016  Florian Henry	    <florian.henry@open-concept.pro>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -123,7 +123,7 @@ if ($result) {
 	$i = 0;
 	while ( $i < $num ) {
 		$obj = $db->fetch_object($result);
-		// contrôles
+		// contrôles
 		$compta_soc = (! empty($obj->code_compta_fournisseur)) ? $obj->code_compta_fournisseur : $cptfour;
 		$compta_prod = $obj->compte;
 		if (empty($compta_prod)) {
@@ -164,6 +164,19 @@ if ($action == 'writebookkeeping') {
 	$error = 0;
 
 	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));
+	
+	$companystatic->id = $tabcompany[$key]['id'];
+			$companystatic->name = $tabcompany[$key]['name'];
+			$companystatic->client = $tabcompany[$key]['code_client'];
+	
+	
 		foreach ( $tabttc[$key] as $k => $mt ) {
 			// get compte id and label
 
@@ -175,7 +188,7 @@ if ($action == 'writebookkeeping') {
 			$bookkeeping->fk_doc = $key;
 			$bookkeeping->fk_docdet = $val["fk_facturefourndet"];
 			$bookkeeping->code_tiers = $tabcompany[$key]['code_fournisseur'];
-			$bookkeeping->label_compte = $tabcompany[$key]['name'];
+			$bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name,16)).' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("Code_tiers");
 			$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER;
 			$bookkeeping->montant = $mt;
 			$bookkeeping->sens = ($mt >= 0) ? 'C' : 'D';
@@ -193,6 +206,8 @@ if ($action == 'writebookkeeping') {
 
 		// Product / Service
 		foreach ( $tabht[$key] as $k => $mt ) {
+		$accountingaccount = new AccountingAccount($db);
+			$accountingaccount->fetch(null, $k);
 			if ($mt) {
 				// get compte id and label
 				$accountingaccount = new AccountingAccount($db);
@@ -205,7 +220,7 @@ if ($action == 'writebookkeeping') {
 					$bookkeeping->fk_doc = $key;
 					$bookkeeping->fk_docdet = $val["fk_facturefourndet"];
 					$bookkeeping->code_tiers = '';
-					$bookkeeping->label_compte = $accountingaccount->label;
+					$bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name,16)). ' - ' . $invoicestatic->refsupplier  . ' - ' . utf8_decode($accountingaccount->label);
 					$bookkeeping->numero_compte = $k;
 					$bookkeeping->montant = $mt;
 					$bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
@@ -236,7 +251,7 @@ if ($action == 'writebookkeeping') {
 				$bookkeeping->fk_doc = $key;
 				$bookkeeping->fk_docdet = $val["fk_facturefourndet"];
 				$bookkeeping->code_tiers = '';
-				$bookkeeping->label_compte = $langs->trans("VAT");
+				$bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name,16)).' - ' . $invoicestatic->refsupplier .' - '. $langs->trans("VAT");
 				$bookkeeping->numero_compte = $k;
 				$bookkeeping->montant = $mt;
 				$bookkeeping->sens = ($mt < 0) ? 'C' : 'D';
@@ -248,7 +263,7 @@ if ($action == 'writebookkeeping') {
 				$result = $bookkeeping->create($user);
 				if ($result < 0) {
 					$error ++;
-					setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
+					setEventMessages($object->error, $object->errors, 'errors');
 				}
 			}
 		}
@@ -517,5 +532,4 @@ if ($action == 'export_csv') {
 	// End of page
 	llxFooter();
 }
-
 $db->close();

+ 38 - 21
htdocs/accountancy/journal/sellsjournal.php

@@ -7,7 +7,7 @@
  * Copyright (C) 2013-2016	Alexandre Spangaro		<aspangaro.dolibarr@gmail.com>
  * Copyright (C) 2013-2016	Florian Henry			<florian.henry@open-concept.pro>
  * Copyright (C) 2013-2016	Olivier Geffroy			<jeff@jeffinfo.com>
- * Copyright (C) 2014       Raphaël Doursenaud      <rdoursenaud@gpcsolutions.fr>
+ * Copyright (C) 2014       Raphaël Doursenaud      <rdoursenaud@gpcsolutions.fr>
  *
  * 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
@@ -24,9 +24,9 @@
  */
 
 /**
- * \file 		htdocs/accountancy/journal/sellsjournal.php
- * \ingroup 	Advanced accountancy
- * \brief 		Page with sells journal
+ * \file		htdocs/accountancy/journal/sellsjournal.php
+ * \ingroup		Advanced accountancy
+ * \brief		Page with sells journal
  */
 require '../../main.inc.php';
 
@@ -142,15 +142,14 @@ if ($result) {
 
 		// Situation invoices handling
 		$line = new FactureLigne($db);
-		$line->fetch($obj->fdid); // id of line
-		$prev_progress = 0;
+		$line->fetch($obj->rowid);
+		$prev_progress = $line->get_prev_progress();
 		if ($obj->type == Facture::TYPE_SITUATION) {
-		    // Avoid divide by 0
+			// Avoid divide by 0
 			if ($obj->situation_percent == 0) {
 				$situation_ratio = 0;
 			} else {
-		        $prev_progress = $line->get_prev_progress($obj->rowid);   // id of invoice
-			    $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
+				$situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent;
 			}
 		} else {
 			$situation_ratio = 1;
@@ -194,6 +193,14 @@ if ($action == 'writebookkeeping') {
 	$error = 0;
 
 	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"];
+	
+	
 		foreach ( $tabttc[$key] as $k => $mt ) {
 			$bookkeeping = new BookKeeping($db);
 			$bookkeeping->doc_date = $val["date"];
@@ -204,7 +211,8 @@ if ($action == 'writebookkeeping') {
 			$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 = $tabcompany[$key]['name'];
+			$bookkeeping->label_compte = utf8_decode(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;
@@ -234,7 +242,7 @@ if ($action == 'writebookkeeping') {
 					$bookkeeping->fk_docdet = $val["fk_facturedet"];
 					$bookkeeping->code_tiers = '';
 					$bookkeeping->numero_compte = $k;
-					$bookkeeping->label_compte = $accountingaccount->label;
+					$bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name,16)). ' - ' . $invoicestatic->ref  . ' - ' . utf8_decode($accountingaccount->label);
 					$bookkeeping->montant = $mt;
 					$bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
 					$bookkeeping->debit = ($mt < 0) ? $mt : 0;
@@ -264,7 +272,7 @@ if ($action == 'writebookkeeping') {
 				$bookkeeping->fk_docdet = $val["fk_facturedet"];
 				$bookkeeping->code_tiers = '';
 				$bookkeeping->numero_compte = $k;
-				$bookkeeping->label_compte = $langs->trans("VAT");
+				$bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name,16)).' - ' . $invoicestatic->ref .' - '. $langs->trans("VAT");
 				$bookkeeping->montant = $mt;
 				$bookkeeping->sens = ($mt < 0) ? 'D' : 'C';
 				$bookkeeping->debit = ($mt < 0) ? $mt : 0;
@@ -275,7 +283,7 @@ if ($action == 'writebookkeeping') {
 				$result = $bookkeeping->create($user);
 				if ($result < 0) {
 					$error ++;
-					setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors');
+					setEventMessages($object->error, $object->errors, 'errors');
 				}
 			}
 		}
@@ -305,6 +313,9 @@ if ($action == 'export_csv') {
 			$companystatic->name = $tabcompany[$key]['name'];
 			$companystatic->client = $tabcompany[$key]['code_client'];
 
+$invoicestatic->id = $key;
+		$invoicestatic->ref = $val["ref"];
+		
 			$date = dol_print_date($db->jdate($val["date"]), '%d%m%Y');
 
 			foreach ( $tabttc[$key] as $k => $mt ) {
@@ -314,7 +325,8 @@ if ($action == 'export_csv') {
 				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 utf8_decode(dol_trunc($companystatic->name,16)).' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers")  . $sep;
+				//print utf8_decode($companystatic->name) . $sep;
 				print $val["ref"];
 				print "\n";
 			}
@@ -329,7 +341,8 @@ if ($action == 'export_csv') {
 					print $sep;
 					print ($mt < 0 ? 'D' : 'C') . $sep;
 					print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
-					print dol_trunc($accountingaccount_static->label, 32) . $sep;
+					print utf8_decode(dol_trunc($companystatic->name,16)). ' - ' . $invoicestatic->ref  . ' - ' . utf8_decode ( utf8_decode ( $accountingaccount_static->label)) . $sep;
+					//print dol_trunc($accountingaccount_static->label, 32) . $sep;
 					print $val["ref"];
 					print "\n";
 				}
@@ -344,7 +357,8 @@ if ($action == 'export_csv') {
 					print $sep;
 					print ($mt < 0 ? 'D' : 'C') . $sep;
 					print ($mt <= 0 ? price(- $mt) : $mt) . $sep;
-					print $langs->trans("VAT") . $sep;
+					print utf8_decode(dol_trunc($companystatic->name,16)).' - ' . $invoicestatic->ref .' - '. $langs->trans("VAT") . $sep;
+					//print $langs->trans("VAT") . $sep;
 					print $val["ref"];
 					print "\n";
 				}
@@ -356,6 +370,9 @@ if ($action == 'export_csv') {
 			$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($db->jdate($val["date"]), 'day');
 
@@ -363,7 +380,7 @@ if ($action == 'export_csv') {
 				print '"' . $date . '"' . $sep;
 				print '"' . $val["ref"] . '"' . $sep;
 				print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep;
-				print '"' . utf8_decode(dol_trunc($companystatic->name,16)).' - ' . $companystatic->ref_client . ' - ' . $langs->trans("Code_tiers") . '"' . $sep;
+				print '"' . utf8_decode(dol_trunc($companystatic->name,16)).' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . '"' . $sep;
 				//print '"' . utf8_decode($companystatic->name) . '"' . $sep;
 				print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep;
 				print '"' . ($mt < 0 ? price(- $mt) : '') . '"';
@@ -393,7 +410,7 @@ if ($action == 'export_csv') {
 					print '"' . $date . '"' . $sep;
 					print '"' . $val["ref"] . '"' . $sep;
 					print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep;
-					print '"' . utf8_decode(dol_trunc($companystatic->name,16)).' - '. $langs->trans("VAT") . '"' . $sep;
+					print '"' . utf8_decode(dol_trunc($companystatic->name,16)).' - ' . $invoicestatic->ref .' - '. $langs->trans("VAT") . '"' . $sep;
 					//print '"' . $langs->trans("VAT") . '"' . $sep;
 					print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep;
 					print '"' . ($mt >= 0 ? price($mt) : '') . '"';
@@ -481,7 +498,7 @@ if ($action == 'export_csv') {
 			print "<td>" . length_accounta($k);
 			//print "</td><td>" . $langs->trans("ThirdParty");
 			//print ' (' . $companystatic->getNomUrl(0, 'customer', 16) . ')';
-			print "<td>" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref_client . ' - ' . $langs->trans("Code_tiers"). "</td>";
+			print "<td>" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers"). "</td>";
 			print "</td><td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>";
 			print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>";
 		}
@@ -498,7 +515,7 @@ if ($action == 'export_csv') {
 				print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
 				print "<td>" . length_accountg($k) . "</td>";
 				//print "<td>" . $accountingaccount->label . "</td>";
-				print "<td>" . $companystatic->getNomUrl(0, 'customer', 16). ' - ' . $invoicestatic->ref_client  . ' - ' . utf8_decode ( utf8_decode ( $accountingaccount->label)) . "</td>";
+				print "<td>" . $companystatic->getNomUrl(0, 'customer', 16). ' - ' . $invoicestatic->ref  . ' - ' . utf8_decode ( utf8_decode ( $accountingaccount->label)) . "</td>";
 				print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>";
 				print "<td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>";
 				print "</tr>";
@@ -512,7 +529,7 @@ if ($action == 'export_csv') {
 				print "<td>" . $date . "</td>";
 				print "<td>" . $invoicestatic->getNomUrl(1) . "</td>";
 				print "<td>" . length_accountg($k) . "</td>";
-				print "<td>" . $companystatic->getNomUrl(0, 'customer', 16). ' - ' . $invoicestatic->ref_client .' - '. $langs->trans("VAT")  . "</td>";
+				print "<td>" . $companystatic->getNomUrl(0, 'customer', 16). ' - ' . $invoicestatic->ref .' - '. $langs->trans("VAT")  . "</td>";
 				//print "<td>" . $langs->trans("VAT") . "</td>";
 				print "<td align='right'>" . ($mt < 0 ? price(- $mt) : '') . "</td>";
 				print "<td align='right'>" . ($mt >= 0 ? price($mt) : '') . "</td>";

+ 1 - 66
htdocs/admin/bank.php

@@ -1,6 +1,6 @@
 <?php
 /* Copyright (C) 2009       Laurent Destailleur        <eldy@users.sourceforge.net>
- * Copyright (C) 2010-2013  Juanjo Menent	       <jmenent@2byte.es>
+ * Copyright (C) 2010-2016  Juanjo Menent	       <jmenent@2byte.es>
  * Copyright (C) 2013-2014  Philippe Grand             <philippe.grand@atoo-net.com>
  * Copyright (C) 2015       Jean-François Ferry         <jfefe@aternatik.fr>
  *
@@ -46,24 +46,6 @@ $action = GETPOST('action','alpha');
  * Actions
  */
 
-if ($action == 'set_BANK_CHEQUERECEIPT_FREE_TEXT')
-{
-	$freetext = GETPOST('BANK_CHEQUERECEIPT_FREE_TEXT');	// No alpha here, we want exact string
-
-    $res = dolibarr_set_const($db, "BANK_CHEQUERECEIPT_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity);
-
-	if (! $res > 0) $error++;
-
- 	if (! $error)
-    {
-        setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
-    }
-    else
-    {
-        setEventMessages($langs->trans("Error"), null, 'errors');
-    }
-}
-
 //Order display of bank account
 if ($action == 'setbankorder')
 {
@@ -89,58 +71,13 @@ $form=new Form($db);
 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
 print load_fiche_titre($langs->trans("BankSetupModule"),$linkback,'title_setup');
 
-
-print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
-print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-print '<input type="hidden" name="action" value="set_BANK_CHEQUERECEIPT_FREE_TEXT">';
-
 $head = bank_admin_prepare_head(null);
 dol_fiche_head($head, 'general', $langs->trans("BankSetupModule"), 0, 'account');
 
-print '<table class="noborder" width="100%">';
-print '<tr class="liste_titre">';
-print '<td>'.$langs->trans("Parameters").'</td>';
-print '<td align="center" width="60">&nbsp;</td>';
-print '<td width="80">&nbsp;</td>';
-print "</tr>\n";
 $var=true;
 
 $var=! $var;
 
-print '<tr '.$bc[$var].'><td colspan="2">';
-print $langs->trans("FreeLegalTextOnChequeReceipts").' ('.$langs->trans("AddCRIfTooLong").')<br>';
-$variablename='BANK_CHEQUERECEIPT_FREE_TEXT';
-if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
-{
-    print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
-}
-else
-{
-    include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
-    $doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_details');
-    print $doleditor->Create();
-}
-print '</td><td align="right">';
-print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
-print "</td></tr>\n";
-print '</table>';
-print "<br>";
-
-/*
-$var=!$var;
-print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
-print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
-print "<input type=\"hidden\" name=\"action\" value=\"set_BANK_CHEQUERECEIPT_DRAFT_WATERMARK\">";
-print '<tr '.$bc[$var].'><td colspan="2">';
-print $langs->trans("WatermarkOnDraftChequeReceipt").'<br>';
-print '<input size="50" class="flat" type="text" name="BANK_CHEQUERECEIPT_DRAFT_WATERMARK" value="'.$conf->global->BANK_CHEQUERECEIPT_DRAFT_WATERMARK.'">';
-print '</td><td align="right">';
-print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
-print "</td></tr>\n";
-print '</form>';
-*/
-
-
 //Show bank account order
 print load_fiche_titre($langs->trans("BankOrderShow"));
 
@@ -202,8 +139,6 @@ print '</table>'."\n";
 
 dol_fiche_end();
 
-print '</form>';
-
 llxFooter();
 
 $db->close();

+ 287 - 0
htdocs/admin/chequereceipts.php

@@ -0,0 +1,287 @@
+<?php
+/* Copyright (C) 2009       Laurent Destailleur        <eldy@users.sourceforge.net>
+ * Copyright (C) 2010-2016  Juanjo Menent	       <jmenent@2byte.es>
+ * Copyright (C) 2013-2014  Philippe Grand             <philippe.grand@atoo-net.com>
+ * Copyright (C) 2015       Jean-François Ferry         <jfefe@aternatik.fr>
+ *
+ * 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
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+/**
+ *      \file       htdocs/admin/bank.php
+ *		\ingroup    bank
+ *		\brief      Page to setup the bank module
+ */
+
+require '../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php';
+
+$langs->load("admin");
+$langs->load("companies");
+$langs->load("bills");
+$langs->load("other");
+$langs->load("banks");
+
+if (!$user->admin)
+  accessforbidden();
+
+$action = GETPOST('action','alpha');
+$value = GETPOST('value','alpha');
+
+
+if (empty($conf->global->CHEQUERECEIPTS_ADDON)) $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipts_mint.php';
+
+
+
+/*
+ * Actions
+ */
+
+if ($action == 'updateMask')
+{
+	$maskconstchequereceipts=GETPOST('maskconstchequereceipts','alpha');
+	$maskchequereceipts=GETPOST('maskchequereceipts','alpha');
+	if ($maskconstchequereceipts) $res = dolibarr_set_const($db,$maskconstchequereceipts,$maskchequereceipts,'chaine',0,'',$conf->entity);
+
+	if (! $res > 0) $error++;
+
+	if (! $error)
+	{
+		setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
+	}
+	else
+	{
+		setEventMessages($langs->trans("Error"), null, 'errors');
+	}
+}
+
+if ($action == 'setmod')
+{
+	dolibarr_set_const($db, "CHEQUERECEIPTS_ADDON",$value,'chaine',0,'',$conf->entity);
+}
+
+if ($action == 'set_BANK_CHEQUERECEIPT_FREE_TEXT')
+{
+	$freetext = GETPOST('BANK_CHEQUERECEIPT_FREE_TEXT');	// No alpha here, we want exact string
+
+    $res = dolibarr_set_const($db, "BANK_CHEQUERECEIPT_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity);
+
+	if (! $res > 0) $error++;
+
+ 	if (! $error)
+    {
+        setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
+    }
+    else
+    {
+        setEventMessages($langs->trans("Error"), null, 'errors');
+    }
+}
+
+/*
+ * view
+ */
+
+$dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
+llxHeader("",$langs->trans("BankSetupModule"));
+
+$form=new Form($db);
+
+$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
+print load_fiche_titre($langs->trans("BankSetupModule"),$linkback,'title_setup');
+
+$head = bank_admin_prepare_head(null);
+dol_fiche_head($head, 'checkreceipts', $langs->trans("BankSetupModule"), 0, 'account');
+
+/*
+ *  Numbering module
+ */
+
+print load_fiche_titre($langs->trans("ChequeReceiptsNumberingModule"), '', '');
+
+print '<table class="noborder" width="100%">';
+print '<tr class="liste_titre">';
+print '<td>'.$langs->trans("Name").'</td>';
+print '<td>'.$langs->trans("Description").'</td>';
+print '<td class="nowrap">'.$langs->trans("Example").'</td>';
+print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
+print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
+print '</tr>'."\n";
+
+clearstatcache();
+
+foreach ($dirmodels as $reldir)
+{
+	$dir = dol_buildpath($reldir."core/modules/cheque/");
+	if (is_dir($dir))
+	{
+		$handle = opendir($dir);
+		if (is_resource($handle))
+		{
+			$var=true;
+
+			while (($file = readdir($handle))!==false)
+			{
+				if (! is_dir($dir.$file) || (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS'))
+				{
+					$filebis = $file;
+					$name = substr($file, 4, dol_strlen($file) -16);
+					$classname = preg_replace('/\.php$/','',$file);
+					// For compatibility
+					if (! is_file($dir.$filebis))
+					{
+						$filebis = $file."/".$file.".modules.php";
+						$classname = "mod_chequereceipt_".$file;
+					}
+					// Check if there is a filter on country
+					preg_match('/\-(.*)_(.*)$/',$classname,$reg);
+					if (! empty($reg[2]) && $reg[2] != strtoupper($mysoc->country_code)) continue;
+
+					$classname = preg_replace('/\-.*$/','',$classname);
+					if (! class_exists($classname) && is_readable($dir.$filebis) && (preg_match('/mod_/',$filebis) || preg_match('/mod_/',$classname)) && substr($filebis, dol_strlen($filebis)-3, 3) == 'php')
+					{
+						// Charging the numbering class
+						require_once $dir.$filebis;
+
+						$module = new $classname($db);
+
+						// Show modules according to features level
+						if ($module->version == 'development'  && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
+						if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
+
+						if ($module->isEnabled())
+						{
+							$var = !$var;
+							print '<tr '.$bc[$var].'><td width="100">';
+							print (empty($module->name)?$name:$module->name);
+							print "</td><td>\n";
+
+							print $module->info();
+
+							print '</td>';
+
+							// Show example of numbering module
+							print '<td class="nowrap">';
+							$tmp=$module->getExample();
+							if (preg_match('/^Error/',$tmp)) print '<div class="error">'.$langs->trans($tmp).'</div>';
+							elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
+							else print $tmp;
+							print '</td>'."\n";
+
+							print '<td align="center">';
+							if ($conf->global->CHEQUERECEIPTS_ADDON == $file || $conf->global->CHEQUERECEIPTS_ADDON.'.php' == $file)
+							{
+								print img_picto($langs->trans("Activated"),'switch_on');
+							}
+							else
+							{
+								print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&value='.preg_replace('/\.php$/','',$file).'&scandir='.$module->scandir.'&label='.urlencode($module->name).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
+							}
+							print '</td>';
+
+							$chequereceipts=new RemiseCheque($db);
+							$chequereceipts->initAsSpecimen();
+
+							// Example
+							$htmltooltip='';
+							$htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
+							$nextval=$module->getNextValue($mysoc,$chequereceipts);
+							if ("$nextval" != $langs->trans("NotAvailable")) {  // Keep " on nextval
+								$htmltooltip.=$langs->trans("NextValue").': ';
+								if ($nextval) {
+									if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
+										$nextval = $langs->trans($nextval);
+									$htmltooltip.=$nextval.'<br>';
+								} else {
+									$htmltooltip.=$langs->trans($module->error).'<br>';
+								}
+							}
+
+							print '<td align="center">';
+							print $form->textwithpicto('',$htmltooltip,1,0);
+
+							if ($conf->global->CHEQUERECEIPTS_ADDON.'.php' == $file)  // If module is the one used, we show existing errors
+							{
+								if (! empty($module->error)) dol_htmloutput_mesg($module->error,'','error',1);
+							}
+
+							print '</td>';
+
+							print "</tr>\n";
+
+						}
+					}
+				}
+			}
+			closedir($handle);
+		}
+	}
+}
+
+print '</table>';
+
+print '<br>';
+
+
+/*
+ * Other options
+ *
+ */
+print load_fiche_titre($langs->trans("OtherOptions"),'','');
+
+print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
+print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+print '<input type="hidden" name="action" value="set_BANK_CHEQUERECEIPT_FREE_TEXT">';
+
+print '<table class="noborder" width="100%">';
+print '<tr class="liste_titre">';
+print '<td>'.$langs->trans("Parameters").'</td>';
+print '<td align="center" width="60">&nbsp;</td>';
+print '<td width="80">&nbsp;</td>';
+print "</tr>\n";
+$var=true;
+
+$var=! $var;
+
+print '<tr '.$bc[$var].'><td colspan="2">';
+print $langs->trans("FreeLegalTextOnChequeReceipts").' ('.$langs->trans("AddCRIfTooLong").')<br>';
+$variablename='BANK_CHEQUERECEIPT_FREE_TEXT';
+if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
+{
+    print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
+}
+else
+{
+    include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
+    $doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_details');
+    print $doleditor->Create();
+}
+print '</td><td align="right">';
+print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
+print "</td></tr>\n";
+print '</table>';
+print "<br>";
+
+print '</table>'."\n";
+
+dol_fiche_end();
+
+print '</form>';
+
+llxFooter();
+
+$db->close();

+ 5 - 5
htdocs/admin/dict.php

@@ -189,7 +189,7 @@ $tabsql[28]= "SELECT h.rowid as rowid, h.code, h.label, h.affect, h.delay, h.new
 $tabsql[29]= "SELECT rowid   as rowid, code, label, percent, position, active FROM ".MAIN_DB_PREFIX."c_lead_status";
 $tabsql[30]= "SELECT rowid, code, name, paper_size, orientation, metric, leftmargin, topmargin, nx, ny, spacex, spacey, width, height, font_size, custom_x, custom_y, active FROM ".MAIN_DB_PREFIX."c_format_cards";
 $tabsql[31]= "SELECT s.rowid as rowid, pcg_version, s.fk_pays as country_id, c.code as country_code, c.label as country, s.label, s.active FROM ".MAIN_DB_PREFIX."accounting_system as s, ".MAIN_DB_PREFIX."c_country as c WHERE s.fk_pays=c.rowid and c.active=1";
-$tabsql[32]= "SELECT a.rowid as rowid, a.code as code, a.label, a.ranges, a.position, a.fk_country as country_id, c.code as country_code, c.label as country, a.active FROM ".MAIN_DB_PREFIX."c_accounting_category as a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_country=c.rowid and c.active=1";
+$tabsql[32]= "SELECT a.rowid as rowid, a.code as code, a.label, a.range_account, a.position, a.fk_country as country_id, c.code as country_code, c.label as country, a.active FROM ".MAIN_DB_PREFIX."c_accounting_category as a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_country=c.rowid and c.active=1";
 $tabsql[33]= "SELECT rowid, pos, code, label, active FROM ".MAIN_DB_PREFIX."c_hrm_department";
 $tabsql[34]= "SELECT rowid, pos, code, label, c_level, active FROM ".MAIN_DB_PREFIX."c_hrm_function";
 
@@ -300,7 +300,7 @@ $tabfieldvalue[28]= "code,label,affect,delay,newbymonth,country";
 $tabfieldvalue[29]= "code,label,percent,position";
 $tabfieldvalue[30]= "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
 $tabfieldvalue[31]= "pcg_version,country,label";
-$tabfieldvalue[32]= "code,label,range,position,country";
+$tabfieldvalue[32]= "code,label,range_account,position,country";
 $tabfieldvalue[33]= "code,label";
 $tabfieldvalue[34]= "code,label";
 
@@ -337,7 +337,7 @@ $tabfieldinsert[28]= "code,label,affect,delay,newbymonth,fk_country";
 $tabfieldinsert[29]= "code,label,percent,position";
 $tabfieldinsert[30]= "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
 $tabfieldinsert[31]= "pcg_version,fk_pays,label";
-$tabfieldinsert[32]= "code,label,range,position,fk_country";
+$tabfieldinsert[32]= "code,label,range_account,position,fk_country";
 $tabfieldinsert[33]= "code,label";
 $tabfieldinsert[34]= "code,label";
 
@@ -998,7 +998,7 @@ if ($id)
             if ($fieldlist[$field]=='sortorder')       { $valuetoshow=$langs->trans("SortOrder"); }
 	        if ($fieldlist[$field]=='short_label')     { $valuetoshow=$langs->trans("ShortLabel"); }
             if ($fieldlist[$field]=='type_template')   { $valuetoshow=$langs->trans("TypeOfTemplate"); }
-			if ($fieldlist[$field]=='range')   		   { $valuetoshow=$langs->trans("Range"); }
+			if ($fieldlist[$field]=='range_account')   { $valuetoshow=$langs->trans("Range"); }
 
             if ($id == 2)	// Special cas for state page
             {
@@ -1166,7 +1166,7 @@ if ($id)
                 if ($fieldlist[$field]=='sortorder')       { $valuetoshow=$langs->trans("SortOrder"); }
 	            if ($fieldlist[$field]=='short_label')     { $valuetoshow=$langs->trans("ShortLabel"); }
             	if ($fieldlist[$field]=='type_template')   { $valuetoshow=$langs->trans("TypeOfTemplate"); }
-				if ($fieldlist[$field]=='range')   		   { $valuetoshow=$langs->trans("Range"); }
+				if ($fieldlist[$field]=='range_account')   { $valuetoshow=$langs->trans("Range"); }
 
                 // Affiche nom du champ
                 if ($showfield)

+ 1 - 1
htdocs/compta/facture/class/facture-rec.class.php

@@ -36,7 +36,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
 /**
  *	Classe de gestion des factures recurrentes/Modeles
  */
-class FactureRec extends Facture
+class FactureRec extends CommonInvoice
 {
 	public $element='facturerec';
 	public $table_element='facture_rec';

+ 8 - 8
htdocs/compta/paiement/cheque/card.php

@@ -2,7 +2,7 @@
 /* Copyright (C) 2006		Rodolphe Quiedeville	<rodolphe@quiedeville.org>
  * Copyright (C) 2007-2011	Laurent Destailleur		<eldy@users.sourceforge.net>
  * Copyright (C) 2009-2012	Regis Houssin			<regis.houssin@capnetworks.com>
- * Copyright (C) 2011		Juanjo Menent			<jmenent@2byte.es>
+ * Copyright (C) 2011-2016	Juanjo Menent			<jmenent@2byte.es>
  * Copyright (C) 2013 		Philippe Grand      	<philippe.grand@atoo-net.com>
  * Copyright (C) 2015	    Alexandre Spangaro      <aspangaro.dolibarr@gmail.com>
  *
@@ -44,7 +44,7 @@ $action=GETPOST('action', 'alpha');
 $confirm=GETPOST('confirm', 'alpha');
 
 // Security check
-$fieldname = (! empty($ref)?'number':'rowid');
+$fieldname = (! empty($ref)?'ref':'rowid');
 if ($user->societe_id) $socid=$user->societe_id;
 $result = restrictedArea($user, 'cheque', $id, 'bordereau_cheque','','',$fieldname);
 
@@ -112,9 +112,9 @@ if ($action == 'setref' && $user->rights->banque->cheque)
 	$result = $object->fetch(GETPOST('id','int'));
 	if ($result > 0)
 	{
-		$number=GETPOST('number');
+		$ref=GETPOST('ref');
 
-		$result=$object->set_number($user,$number);
+		$result=$object->set_number($user,$ref);
 		if ($result < 0)
 		{
 			setEventMessages($object->error, $object->errors, 'errors');
@@ -280,7 +280,7 @@ else if ($action == 'remove_file' && $user->rights->banque->cheque)
 
 		$langs->load("other");
 
-		$file=$dir.get_exdir($object->number,0,1,0,$object,'cheque') . GETPOST('file');
+		$file=$dir.get_exdir($object->ref,0,1,0,$object,'cheque') . GETPOST('file');
 		$ret=dol_delete_file($file,0,0,0,$object);
 		if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
 		else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
@@ -576,13 +576,13 @@ else
 		print '<form name="setdate" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
 		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
 		print '<input type="hidden" name="action" value="setref">';
-		print '<input type="text" name="number" value="'.$object->number.'">';
+		print '<input type="text" name="ref" value="'.$object->ref.'">';
 		print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
 		print '</form>';
 	}
 	else
 	{
-	    print $form->showrefnav($object,'ref',$linkback, 1, 'number');
+	    print $form->showrefnav($object,'ref',$linkback, 1, 'ref');
 	}
 
 	print '</td>';
@@ -796,7 +796,7 @@ if ($action != 'new')
 	if ($object->statut == 1)
 	{
 		$filename=dol_sanitizeFileName($object->ref);
-		$filedir=$dir.get_exdir($object->number,0,1,0,$object,'cheque') . dol_sanitizeFileName($object->ref);
+		$filedir=$dir.get_exdir($object->ref,0,1,0,$object,'cheque') . dol_sanitizeFileName($object->ref);
 		$urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id;
 
 		$formfile->show_documents('remisecheque', $filename, $filedir, $urlsource, 1, 1);

+ 115 - 47
htdocs/compta/paiement/cheque/class/remisecheque.class.php

@@ -2,7 +2,7 @@
 /* Copyright (C) 2006      Rodolphe Quiedeville <rodolphe@quiedeville.org>
  * Copyright (C) 2007-2011 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2005-2009 Regis Houssin        <regis.houssin@capnetworks.com>
- * Copyright (C) 2011-2015 Juanjo Menent        <jmenent@2byte.es>
+ * Copyright (C) 2011-2016 Juanjo Menent        <jmenent@2byte.es>
  * Copyright (C) 2015      Marcos García        <marcosgdf@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -47,7 +47,7 @@ class RemiseCheque extends CommonObject
 	public $account_label;
 	public $author_id;
 	public $nbcheque;
-	public $number;
+	public $ref;
 
 	/**
 	 *	Constructor
@@ -72,14 +72,14 @@ class RemiseCheque extends CommonObject
 	{
 		global $conf;
 
-		$sql = "SELECT bc.rowid, bc.datec, bc.fk_user_author, bc.fk_bank_account, bc.amount, bc.number, bc.statut, bc.nbcheque, bc.ref_ext";
+		$sql = "SELECT bc.rowid, bc.datec, bc.fk_user_author, bc.fk_bank_account, bc.amount, bc.ref, bc.statut, bc.nbcheque, bc.ref_ext";
 		$sql.= ", bc.date_bordereau as date_bordereau";
 		$sql.= ", ba.label as account_label";
 		$sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc";
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON bc.fk_bank_account = ba.rowid";
 		$sql.= " WHERE bc.entity = ".$conf->entity;
 		if ($id)  $sql.= " AND bc.rowid = ".$id;
-		if ($ref) $sql.= " AND bc.number = '".$this->db->escape($ref)."'";
+		if ($ref) $sql.= " AND bc.ref = '".$this->db->escape($ref)."'";
 
 		dol_syslog("RemiseCheque::fetch", LOG_DEBUG);
 		$resql = $this->db->query($sql);
@@ -99,13 +99,12 @@ class RemiseCheque extends CommonObject
 
 				if ($this->statut == 0)
 				{
-					$this->number         = "(PROV".$this->id.")";
+					$this->ref         = "(PROV".$this->id.")";
 				}
 				else
 				{
-					$this->number         = $obj->number;
+					$this->ref         = $obj->ref;
 				}
-				$this->ref            = $this->number;
 
 			}
 			$this->db->free($resql);
@@ -124,7 +123,7 @@ class RemiseCheque extends CommonObject
 	 *
 	 *	@param	User	$user 			User making creation
 	 *	@param  int		$account_id 	Bank account for cheque receipt
-	 *  @param  int		$limit          Limit number of cheque to this
+	 *  @param  int		$limit          Limit ref of cheque to this
 	 *  @param	array	$toRemise		array with cheques to remise
 	 *	@return	int						<0 if KO, >0 if OK
 	 */
@@ -146,7 +145,7 @@ class RemiseCheque extends CommonObject
 		$sql.= ", fk_bank_account";
 		$sql.= ", statut";
 		$sql.= ", amount";
-		$sql.= ", number";
+		$sql.= ", ref";
 		$sql.= ", entity";
 		$sql.= ", nbcheque";
 		$sql.= ", ref_ext";
@@ -177,7 +176,7 @@ class RemiseCheque extends CommonObject
 			if ($this->id > 0 && $this->errno == 0)
 			{
 				$sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
-				$sql.= " SET number='(PROV".$this->id.")'";
+				$sql.= " SET ref='(PROV".$this->id.")'";
 				$sql.= " WHERE rowid='".$this->id."';";
 
 				dol_syslog("RemiseCheque::Create", LOG_DEBUG);
@@ -345,13 +344,13 @@ class RemiseCheque extends CommonObject
 		$this->errno = 0;
 
 		$this->db->begin();
-
-		$numref=$this->getNextNumber();
+		
+		$numref = $this->getNextNumRef();
 
 		if ($this->errno == 0 && $numref)
 		{
 			$sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
-			$sql.= " SET statut = 1, number = '".$numref."'";
+			$sql.= " SET statut = 1, ref = '".$numref."'";
 			$sql.= " WHERE rowid = ".$this->id;
 			$sql.= " AND entity = ".$conf->entity;
 			$sql.= " AND statut = 0";
@@ -364,7 +363,7 @@ class RemiseCheque extends CommonObject
 
 				if ($num == 1)
 				{
-				    $this->number = $numref;
+				    $this->ref = $numref;
 					$this->statut = 1;
 				}
 				else
@@ -394,46 +393,92 @@ class RemiseCheque extends CommonObject
 		}
 	}
 
-
 	/**
-	 * Old module for cheque receipt numbering
+	 *      Return next reference of cheque receipts not already used (or last reference)
+	 *      according to numbering module defined into constant FACTURE_ADDON
 	 *
-	 * @return 	int		Next number of cheque
+	 *      @param     string		$mode		'next' for next value or 'last' for last value
+	 *      @return    string					free ref or last ref
 	 */
-	function getNextNumber()
+	function getNextNumRef($mode='next')
 	{
-		global $conf;
-
-		$num=0;
+		global $conf, $db, $langs, $mysoc;
+		$langs->load("bills");
 
-		// We use +0 to convert varchar to number for mysql, use ::integer for postgres.
-		// We must found a generic solution (Use a $db->toint function ?)
-		$sql = "SELECT ";
-		if ($this->db->type == 'pgsql') $sql.="MAX(number::integer)";
-		else $sql.="MAX(number+0)";
-		$sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque";
-		$sql.= " WHERE entity = ".$conf->entity;
-		$sql.= " AND number not like '(%'";
+		// Clean parameters (if not defined or using deprecated value)
+		if (empty($conf->global->CHEQUERECEIPTS_ADDON)) $conf->global->CHEQUERECEIPTS_ADDON='mod_chequereceipt_mint';
+		else if ($conf->global->CHEQUERECEIPTS_ADDON=='thyme') $conf->global->CHEQUERECEIPTS_ADDON='mod_chequereceipt_thyme';
+		else if ($conf->global->CHEQUERECEIPTS_ADDON=='mint') $conf->global->CHEQUERECEIPTS_ADDON='mod_chequereceipt_mint';
 
-		dol_syslog("Remisecheque::getNextNumber", LOG_DEBUG);
-		$resql = $this->db->query($sql);
-		if ($resql)
+		if (! empty($conf->global->CHEQUERECEIPTS_ADDON))
 		{
-			$row = $this->db->fetch_row($resql);
-			$num = $row[0];
-			$this->db->free($resql);
+			$mybool=false;
+
+			$file = $conf->global->CHEQUERECEIPTS_ADDON.".php";
+			$classname = $conf->global->CHEQUERECEIPTS_ADDON;
+
+			// Include file with class
+			$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
+
+			foreach ($dirmodels as $reldir) {
+
+				$dir = dol_buildpath($reldir."core/modules/cheque/");
+
+				// Load file with numbering class (if found)
+				if (is_file($dir.$file) && is_readable($dir.$file))
+				{
+					$mybool |= include_once $dir . $file;
+				}
+			}
+
+			// For compatibility
+			if (! $mybool)
+			{
+				$file = $conf->global->CHEQUERECEIPTS_ADDON.".php";
+				$classname = "mod_chequereceipt_".$conf->global->CHEQUERECEIPTS_ADDON;
+				$classname = preg_replace('/\-.*$/','',$classname);
+				// Include file with class
+				foreach ($conf->file->dol_document_root as $dirroot)
+				{
+					$dir = $dirroot."/core/modules/cheque/";
+
+					// Load file with numbering class (if found)
+					if (is_file($dir.$file) && is_readable($dir.$file)) {
+						$mybool |= include_once $dir . $file;
+					}
+				}
+			}
+
+			if (! $mybool)
+			{
+				dol_print_error('',"Failed to include file ".$file);
+				return '';
+			}
+
+			$obj = new $classname();
+			$numref = "";
+			$numref = $obj->getNextValue($mysoc,$this);
+
+			/**
+			 * $numref can be empty in case we ask for the last value because if there is no invoice created with the
+			 * set up mask.
+			 */
+			if ($mode != 'last' && !$numref) {
+				dol_print_error($db,"ChequeReceipts::getNextNumRef ".$obj->error);
+				return "";
+			}
+
+			return $numref;
 		}
 		else
 		{
-			$this->errno = -1034;
-			dol_syslog("Remisecheque::Validate Erreur SELECT ($this->errno)", LOG_ERR);
+			$langs->load("errors");
+			print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete");
+			return "";
 		}
-
-		$num++;
-
-		return $num;
 	}
 
+
 	/**
      *      Load indicators for dashboard (this->nbtodo and this->nbtodolate)
      *
@@ -540,7 +585,7 @@ class RemiseCheque extends CommonObject
 				}
 			}
 			$docmodel->nbcheque = $this->nbcheque;
-			$docmodel->number = $this->number;
+			$docmodel->ref = $this->ref;
 			$docmodel->amount = $this->amount;
 			$docmodel->date   = $this->date_bordereau;
 
@@ -552,7 +597,7 @@ class RemiseCheque extends CommonObject
 			// We save charset_output to restore it because write_file can change it if needed for
 			// output format that does not support UTF8.
 			$sav_charseSupprimert_output=$outputlangs->charset_output;
-			$result=$docmodel->write_file($this, $conf->banque->dir_output.'/bordereau', $this->number, $outputlangs);
+			$result=$docmodel->write_file($this, $conf->banque->dir_output.'/bordereau', $this->ref, $outputlangs);
 			if ($result > 0)
 			{
 				//$outputlangs->charset_output=$sav_charset_output;
@@ -838,18 +883,18 @@ class RemiseCheque extends CommonObject
     }
 
 	/**
-	 *      Set the number of bordereau
+	 *      Set the ref of bordereau
 	 *
 	 *      @param	User		$user           Object user
-	 *      @param  int   $number         number of bordereau
+	 *      @param  int   $ref         ref of bordereau
 	 *      @return int                 		<0 if KO, >0 if OK
 	 */
-	function set_number($user, $number)
+	function set_number($user, $ref)
 	{
 		if ($user->rights->banque->cheque)
 		{
 			$sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
-			$sql.= " SET number = '".$number."'" ;
+			$sql.= " SET ref = '".$ref."'" ;
 			$sql.= " WHERE rowid = ".$this->id;
 
 			dol_syslog("RemiseCheque::set_number", LOG_DEBUG);
@@ -870,6 +915,29 @@ class RemiseCheque extends CommonObject
 		}
 	}
 
+	/**
+	 *  Initialise an instance with random values.
+	 *  Used to build previews or test instances.
+	 *	id must be 0 if object instance is a specimen.
+	 *
+	 *	@param	string		$option		''=Create a specimen invoice with lines, 'nolines'=No lines
+	 *  @return	void
+	 */
+	function initAsSpecimen($option='')
+	{
+		global $user,$langs,$conf;
+
+		$now=dol_now();
+		$arraynow=dol_getdate($now);
+		$nownotime=dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
+
+		// Initialize parameters
+		$this->id=0;
+		$this->ref = 'SPECIMEN';
+		$this->specimen=1;
+		$this->date_bordereau = $nownotime;
+	}
+
 	/**
 	 *    	Return clicable name (with picto eventually)
 	 *

+ 2 - 1
htdocs/compta/paiement/cheque/index.php

@@ -2,6 +2,7 @@
 /* Copyright (C) 2006      Rodolphe Quiedeville <rodolphe@quiedeville.org>
  * Copyright (C) 2007-2011 Laurent Destailleur  <eldy@users.sourceforge.net>
  * Copyright (C) 2009      Regis Houssin        <regis.houssin@capnetworks.com>
+ * Copyright (C) 2016      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
@@ -94,7 +95,7 @@ print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
 
 $max=10;
 
-$sql = "SELECT bc.rowid, bc.date_bordereau as db, bc.amount, bc.number as ref";
+$sql = "SELECT bc.rowid, bc.date_bordereau as db, bc.amount, bc.ref as ref";
 $sql.= ", bc.statut, bc.nbcheque";
 $sql.= ", ba.label, ba.rowid as bid";
 $sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc";

+ 4 - 3
htdocs/compta/paiement/cheque/list.php

@@ -3,6 +3,7 @@
  * Copyright (C) 2007-2009	Laurent Destailleur		<eldy@users.sourceforge.net>
  * Copyright (C) 2009-2012	Regis Houssin			<regis.houssin@capnetworks.com>
  * Copyright (C) 2014		Alexandre Spangaro		<aspangaro.dolibarr@gmail.com>
+ * Copyright (C) 2016		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
@@ -77,7 +78,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both
 
 llxHeader('',$langs->trans("ChequesReceipts"));
 
-$sql = "SELECT bc.rowid, bc.number as ref, bc.date_bordereau as dp,";
+$sql = "SELECT bc.rowid, bc.ref as ref, bc.date_bordereau as dp,";
 $sql.= " bc.nbcheque, bc.amount, bc.statut,";
 $sql.= " ba.rowid as bid, ba.label";
 $sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc,";
@@ -86,7 +87,7 @@ $sql.= " WHERE bc.fk_bank_account = ba.rowid";
 $sql.= " AND bc.entity = ".$conf->entity;
 
 // Search criteria
-if ($search_ref)			$sql.=" AND bc.number=".$search_ref;
+if ($search_ref)			$sql.=" AND bc.ref=".$search_ref;
 if ($search_account > 0)	$sql.=" AND bc.fk_bank_account=".$search_account;
 if ($search_amount)			$sql.=" AND bc.amount='".$db->escape(price2num(trim($search_amount)))."'";
 if ($month > 0)
@@ -134,7 +135,7 @@ if ($resql)
 	
 	print '<table class="liste">';
 	print '<tr class="liste_titre">';
-	print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"bc.number","",$param,"",$sortfield,$sortorder);
+	print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"bc.ref","",$param,"",$sortfield,$sortorder);
 	print_liste_field_titre($langs->trans("DateCreation"),$_SERVER["PHP_SELF"],"dp","",$param,'align="center"',$sortfield,$sortorder);
 	print_liste_field_titre($langs->trans("Account"),$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder);
 	print_liste_field_titre($langs->trans("NbOfCheques"),$_SERVER["PHP_SELF"],"bc.nbcheque","",$param,'align="right"',$sortfield,$sortorder);

+ 1 - 1
htdocs/contrat/list.php

@@ -321,7 +321,7 @@ if ($resql)
         			print '</div>';
         		}
         	}
-        	else print $langs->trans("NoSalesRepresentativeAffected");
+        	//else print $langs->trans("NoSalesRepresentativeAffected");
         }
         else
         {

+ 3 - 3
htdocs/core/class/html.formaccounting.class.php

@@ -64,7 +64,7 @@ class FormAccounting
 
         if (! empty($mysoc->country_id))
         {
-            $sql = "SELECT c.rowid, c.label as type, c.ranges";
+            $sql = "SELECT c.rowid, c.label as type, c.range_account";
             $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c";
             $sql.= " WHERE c.active = 1";
             $sql.= " AND c.fk_country = ".$mysoc->country_id;
@@ -72,7 +72,7 @@ class FormAccounting
         }
         else
         {
-            $sql = "SELECT c.rowid, c.label as type, c.ranges";
+            $sql = "SELECT c.rowid, c.label as type, c.range_account";
             $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c, ".MAIN_DB_PREFIX."c_country as co";
             $sql.= " WHERE c.active = 1 AND c.fk_country = co.rowid";
             $sql.= " AND co.code = '".$mysoc->country_code."'";
@@ -96,7 +96,7 @@ class FormAccounting
                     print '<option value="'.$obj->rowid.'"';
                     if ($obj->rowid == $selected) print ' selected';
                     print '>'.dol_trunc($obj->type,$maxlen);
-					print ' ('.$obj->ranges.')';
+					print ' ('.$obj->range_account.')';
                     $i++;
                 }
                 print '</select>';

+ 6 - 6
htdocs/core/lib/accounting.lib.php

@@ -1,6 +1,6 @@
 <?php
 /* Copyright (C) 2013-2014 Olivier Geffroy      <jeff@jeffinfo.com>
- * Copyright (C) 2013-2014 Alexandre Spangaro   <aspangaro.dolibarr@gmail.com>
+ * Copyright (C) 2013-2016 Alexandre Spangaro   <aspangaro.dolibarr@gmail.com>
  * Copyright (C) 2014 	   Florian Henry        <florian.henry@open-concept.pro>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -18,9 +18,9 @@
  */
 
 /**
- * 		\file			htdocs/core/lib/account.lib.php
- * 		\ingroup		Accounting Expert
- * 		\brief			Library of accountancy functions
+ * 	\file		htdocs/core/lib/accounting.lib.php
+ * 	\ingroup	Advanced accountancy
+ * 	\brief		Library of accountancy functions
  */
 
 /**
@@ -120,7 +120,7 @@ function length_accountg($account)
 		// Clean parameters
 		$i = strlen($account);
 
-		if ($i >= 2) {
+		if ($i >= 1) {
 			while ( $i < $g ) {
 				$account .= '0';
 
@@ -152,7 +152,7 @@ function length_accounta($accounta)
 		// Clean parameters
 		$i = strlen($accounta);
 
-		if ($i >= 2) {
+		if ($i >= 1) {
 			while ( $i < $a ) {
 				$accounta .= '0';
 

+ 6 - 0
htdocs/core/lib/bank.lib.php

@@ -2,6 +2,7 @@
 /* Copyright (C) 2006-2015	Laurent Destailleur	<eldy@users.sourceforge.net>
  * Copyright (C) 2012		Regis Houssin		<regis.houssin@capnetworks.com>
  * Copyright (C) 2015		Alexandre Spangaro	<aspangaro.dolibarr@gmail.com>
+ * Copyright (C) 2016		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
@@ -111,6 +112,11 @@ function bank_admin_prepare_head($object)
 	$head[$h][2] = 'general';
 	$h++;
 
+    $head[$h][0] = DOL_URL_ROOT . '/admin/chequereceipts.php';
+    $head[$h][1] = $langs->trans("CheckReceiptShort");
+    $head[$h][2] = 'checkreceipts';
+    $h++;
+
 
 	// Show more tabs from modules
 	// Entries must be declared in modules descriptor with line

+ 5 - 5
htdocs/core/lib/functions.lib.php

@@ -3423,26 +3423,26 @@ function price2num($amount,$rounding='',$alreadysqlnb=0)
  * @param   string      $forceunitoutput    'no' or numeric (-3, -6, ...) compared to $unit
  * @return  string                      String to show dimensions
  */
-function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitouput='no')
+function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round=-1, $forceunitoutput='no')
 {
     require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
     
-    if (($forceunitouput == 'no' && $dimension < 1/10000) || (is_numeric($forceunitouput) && $forceunitouput == -6)) 
+    if (($forceunitoutput == 'no' && $dimension < 1/10000) || (is_numeric($forceunitoutput) && $forceunitoutput == -6)) 
     {
         $dimension = $dimension * 1000000;
         $unit = $unit - 6; 
     }
-    elseif (($forceunitouput == 'no' && $dimension < 1/10) || (is_numeric($forceunitouput) && $forceunitouput == -3))
+    elseif (($forceunitoutput == 'no' && $dimension < 1/10) || (is_numeric($forceunitoutput) && $forceunitoutput == -3))
     {
         $dimension = $dimension * 1000;
         $unit = $unit - 3; 
     }
-    elseif (($forceunitouput == 'no' && $dimension > 100000000) || (is_numeric($forceunitouput) && $forceunitouput == 6))
+    elseif (($forceunitoutput == 'no' && $dimension > 100000000) || (is_numeric($forceunitoutput) && $forceunitoutput == 6))
     {
         $dimension = $dimension / 1000000;
         $unit = $unit + 6;
     }
-    elseif (($forceunitouput == 'no' && $dimension > 100000) || (is_numeric($forceunitouput) && $forceunitouput == 3))
+    elseif (($forceunitoutput == 'no' && $dimension > 100000) || (is_numeric($forceunitoutput) && $forceunitoutput == 3))
     {
         $dimension = $dimension / 1000;
         $unit = $unit + 3;

+ 1 - 1
htdocs/core/modules/cheque/doc/pdf_blochet.class.php

@@ -225,7 +225,7 @@ class BordereauChequeBlochet extends ModeleChequeReceipts
 		$pdf->MultiCell(22,2,$outputlangs->transnoentities("Ref"),0,'L');
         $pdf->SetXY(32,15);
 		$pdf->SetFont('','', $default_font_size);
-        $pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->number.($this->ref_ext?" - ".$this->ref_ext:'')), 0, 'L');
+        $pdf->MultiCell(60, 2, $outputlangs->convToOutputCharset($this->ref.($this->ref_ext?" - ".$this->ref_ext:'')), 0, 'L');
 
 		$pdf->SetFont('','', $default_font_size);
         $pdf->SetXY(10,20);

+ 150 - 0
htdocs/core/modules/cheque/mod_chequereceipt_mint.php

@@ -0,0 +1,150 @@
+<?php
+/* Copyright (C) 2015      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
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * or see http://www.gnu.org/
+ */
+
+/**
+ * \file       htdocs/core/modules/cheque/mod_chequereceipts_mint.php
+ * \ingroup    cheque
+ * \brief      File containing class for numbering module Mint
+ */
+
+require_once DOL_DOCUMENT_ROOT .'/core/modules/cheque/modules_chequereceipts.php';
+
+/**
+ *	Class to manage cheque receipts numbering rules Mint
+ */
+class mod_chequereceipt_mint extends ModeleNumRefChequeReceipts
+{
+	var $version='dolibarr';		// 'development', 'experimental', 'dolibarr'
+	var $prefix='CHK';
+	var $error='';
+	var $name='Mint';
+
+
+    /**
+     *  Return description of numbering module
+     *
+     *  @return     string      Text with description
+     */
+    function info()
+    {
+    	global $langs;
+      	return $langs->trans("SimpleNumRefModelDesc",$this->prefix);
+    }
+
+
+	/**
+	 *  Renvoi un exemple de numerotation
+	 *
+	 *  @return     string      Example
+	 */
+	function getExample()
+	{
+		return $this->prefix."0501-0001";
+	}
+
+
+	/**
+	 *  Test si les numeros deje en vigueur dans la base ne provoquent pas de
+	 *  de conflits qui empechera cette numerotation de fonctionner.
+	 *
+	 *  @return     boolean     false si conflit, true si ok
+	 */
+	function canBeActivated()
+	{
+		global $conf,$langs,$db;
+
+		$payyymm=''; $max='';
+
+		$posindice=9;
+		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
+		$sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque";
+		$sql.= " WHERE ref LIKE '".$this->prefix."____-%'";
+		$sql.= " AND entity = ".$conf->entity;
+
+		$resql=$db->query($sql);
+		if ($resql)
+		{
+			$row = $db->fetch_row($resql);
+			if ($row) { $payyymm = substr($row[0],0,6); $max=$row[0]; }
+		}
+		if ($payyymm && ! preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$payyymm))
+		{
+			$langs->load("errors");
+			$this->error=$langs->trans('ErrorNumRefModel', $max);
+			return false;
+		}
+
+		return true;
+	}
+
+	/**
+	 * 	Return next free value
+	 *
+	 *  @param	Societe		$objsoc     Object thirdparty
+	 *  @param  Object		$object		Object we need next value for
+	 *  @return string      			Value if KO, <0 if KO
+	 */
+	function getNextValue($objsoc,$object)
+	{
+		global $db,$conf;
+
+		// D'abord on recupere la valeur max
+		$posindice=9;
+		$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
+		$sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque";
+		$sql.= " WHERE ref like '".$this->prefix."____-%'";
+		$sql.= " AND entity = ".$conf->entity;
+
+		$resql=$db->query($sql);
+		if ($resql)
+		{
+			$obj = $db->fetch_object($resql);
+			if ($obj) $max = intval($obj->max);
+			else $max=0;
+		}
+		else
+		{
+			dol_syslog(__METHOD__, LOG_DEBUG);
+			return -1;
+		}
+
+		//$date=time();
+		$date=$object->date_bordereau;
+		$yymm = strftime("%y%m",$date);
+
+    	if ($max >= (pow(10, 4) - 1)) $num=$max+1;	// If counter > 9999, we do not format on 4 chars, we take number as it is
+    	else $num = sprintf("%04s",$max+1);
+
+		dol_syslog(__METHOD__." return ".$this->prefix.$yymm."-".$num);
+		return $this->prefix.$yymm."-".$num;
+	}
+
+
+	/**
+	 *  Return next free value
+	 *
+	 *  @param	Societe		$objsoc     Object third party
+	 * 	@param	string		$objforref	Object for number to search
+	 *  @return string      			Next free value
+	 */
+	function chequereceipt_get_num($objsoc,$objforref)
+	{
+		return $this->getNextValue($objsoc,$objforref);
+	}
+
+}

+ 140 - 0
htdocs/core/modules/cheque/mod_chequereceipt_thyme.php

@@ -0,0 +1,140 @@
+<?php
+/* Copyright (C) 2015      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
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * or see http://www.gnu.org/
+ */
+
+/**
+ * \file       htdocs/core/modules/cheque/mod_chequereceipts_thyme.php
+ * \ingroup    cheque
+ * \brief      File containing class for numbering module Thyme
+ */
+
+require_once DOL_DOCUMENT_ROOT .'/core/modules/cheque/modules_chequereceipts.php';
+
+
+/**
+ *	Class to manage cheque receipts numbering rules Thyme
+ */
+class mod_chequereceipt_thyme extends ModeleNumRefChequeReceipts
+{
+	var $version='dolibarr';		// 'development', 'experimental', 'dolibarr'
+	var $error = '';
+	var $name = 'Thyme';
+
+
+    /**
+     *  Renvoi la description du modele de numerotation
+     *
+     *  @return     string      Texte descripif
+     */
+	function info()
+    {
+    	global $conf,$langs;
+
+		$langs->load("bills");
+
+		$form = new Form($this->db);
+
+		$texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
+		$texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
+		$texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
+		$texte.= '<input type="hidden" name="action" value="updateMask">';
+		$texte.= '<input type="hidden" name="maskconstchequereceipts" value="CHEQUERECEIPTS_THYME_MASK">';
+		$texte.= '<table class="nobordernopadding" width="100%">';
+
+		$tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("CheckReceiptShort"),$langs->transnoentities("CheckReceiptShort"));
+		$tooltip.=$langs->trans("GenericMaskCodes2");
+		$tooltip.=$langs->trans("GenericMaskCodes3");
+		$tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("CheckReceiptShort"),$langs->transnoentities("CheckReceiptShort"));
+		$tooltip.=$langs->trans("GenericMaskCodes5");
+
+		// Parametrage du prefix
+		$texte.= '<tr><td>'.$langs->trans("Mask").':</td>';
+		$texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskchequereceipts" value="'.$conf->global->CHEQUERECEIPTS_THYME_MASK.'">',$tooltip,1,1).'</td>';
+
+		$texte.= '<td align="left" rowspan="2">&nbsp; <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>';
+
+		$texte.= '</tr>';
+
+		$texte.= '</table>';
+		$texte.= '</form>';
+
+		return $texte;
+    }
+
+    /**
+     *  Renvoi un exemple de numerotation
+     *
+     *  @return     string      Example
+     */
+    function getExample()
+    {
+     	global $conf,$langs,$mysoc;
+
+    	$old_code_client=$mysoc->code_client;
+    	$mysoc->code_client='CCCCCCCCCC';
+     	$numExample = $this->getNextValue($mysoc,'');
+		$mysoc->code_client=$old_code_client;
+
+		if (! $numExample)
+		{
+			$numExample = $langs->trans('NotConfigured');
+		}
+		return $numExample;
+    }
+
+	/**
+	 * 	Return next free value
+	 *
+	 *  @param	Societe		$objsoc     Object thirdparty
+	 *  @param  Object		$object		Object we need next value for
+	 *  @return string      			Value if KO, <0 if KO
+	 */
+    function getNextValue($objsoc,$object)
+    {
+		global $db,$conf;
+
+		require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php';
+
+		// We get cursor rule
+		$mask=$conf->global->CHEQUERECEIPTS_THYME_MASK;
+
+		if (! $mask)
+		{
+			$this->error='NotConfigured';
+			return 0;
+		}
+
+		$numFinal=get_next_value($db,$mask,'bordereau_cheque','ref','',$objsoc,$object->date_bordereau);
+
+		return  $numFinal;
+	}
+
+
+	/**
+	 *  Return next free value
+	 *
+	 *  @param	Societe		$objsoc     Object third party
+	 * 	@param	string		$objforref	Object for number to search
+	 *  @return string      			Next free value
+     */
+    function chequereceipt_get_num($objsoc,$objforref)
+    {
+        return $this->getNextValue($objsoc,$objforref);
+    }
+
+}
+

+ 83 - 1
htdocs/core/modules/cheque/modules_chequereceipts.php

@@ -30,10 +30,92 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';   // Requis car utilise dans les classes qui heritent
 
+/**
+ *  \class      ModeleNumRefChequeReceipts
+ *  \brief      Cheque Receipts numbering references mother class
+ */
+abstract class ModeleNumRefChequeReceipts
+{
+	var $error='';
+
+	/**
+	 *	Return if a module can be used or not
+	 *
+	 *	@return		boolean     true if module can be used
+	 */
+	function isEnabled()
+	{
+		return true;
+	}
+
+	/**
+	 *	Return the default description of numbering module
+	 *
+	 *	@return     string      Texte descripif
+	 */
+	function info()
+	{
+		global $langs;
+		$langs->load("bills");
+		return $langs->trans("NoDescription");
+	}
+
+	/**
+	 *	Return numbering example
+	 *
+	 *	@return     string      Example
+	 */
+	function getExample()
+	{
+		global $langs;
+		$langs->load("bills");
+		return $langs->trans("NoExample");
+	}
+
+	/**
+	 *  Test if the existing numbers in the database do not cause conflicts that would prevent this numbering run.
+	 *
+	 *	@return     boolean     false si conflit, true si ok
+	 */
+	function canBeActivated()
+	{
+		return true;
+	}
+
+	/**
+	 *	Returns the next value
+	 *
+	 *	@param	Societe		$objsoc     Object thirdparty
+	 *	@param	Object		$object		Object we need next value for
+	 *	@return	string      Valeur
+	 */
+	function getNextValue($objsoc,$object)
+	{
+		global $langs;
+		return $langs->trans("NotAvailable");
+	}
+
+	/**
+	 *	Returns the module numbering version
+	 *
+	 *	@return     string      Value
+	 */
+	function getVersion()
+	{
+		global $langs;
+		$langs->load("admin");
+
+		if ($this->version == 'development') return $langs->trans("VersionDevelopment");
+		if ($this->version == 'experimental') return $langs->trans("VersionExperimental");
+		if ($this->version == 'dolibarr') return DOL_VERSION;
+		if ($this->version) return $this->version;
+		return $langs->trans("NotAvailable");
+	}
+}
 
 /**
  *	\class      ModeleChequeReceipts
- *	\brief      Classe mere des modeles de facture
+ *	\brief      Classe mere des modeles de 
  */
 abstract class ModeleChequeReceipts extends CommonDocGenerator
 {

+ 21 - 1
htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php

@@ -484,6 +484,22 @@ class doc_generic_project_odt extends ModelePDFProjects
 
 				dol_mkdir($conf->projet->dir_temp);
 
+				// If PROJECTLEADER contact defined on project, we use it
+				$usecontact=false;
+				$arrayidcontact=$object->getIdContact('external','PROJECTLEADER');
+				if (count($arrayidcontact) > 0)
+				{
+					$usecontact=true;
+					$result=$object->fetch_contact($arrayidcontact[0]);
+				}
+
+				// Recipient name
+				if (! empty($usecontact))
+				{
+        			// if we have a PROJECTLEADER contact and we dont use it as recipient we store the contact object for later use
+        			$contactobject = $object->contact;
+				}
+
 				$socobject=$object->thirdparty;
 
 				// Make substitution
@@ -529,8 +545,12 @@ class doc_generic_project_odt extends ModelePDFProjects
 				$array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
 				$array_objet=$this->get_substitutionarray_object($object,$outputlangs);
 				$array_other=$this->get_substitutionarray_other($outputlangs);
+                // retrieve contact information for use in project as contact_xxx tags
+        		$array_project_contact = array();
+        		if ($usecontact)
+            			$array_project_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact');
 
-				$tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_objet,$array_other);
+				$tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_project_contact);
 				complete_substitutions_array($tmparray, $outputlangs, $object);
 				// Call the ODTSubstitution hook
 				$parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray);

+ 1 - 1
htdocs/core/search_page.php

@@ -111,7 +111,7 @@ else
 	if (! empty($conf->user->enabled) && $user->rights->user->user->lire)
     {
         $langs->load("users");
-        $searchform.=printSearchForm(DOL_URL_ROOT.'/user/list.php', DOL_URL_ROOT.'/user/list.php', $langs->trans("Users"), 'user', 'sall', 'M', 'searchleftuser', img_object('','user'));
+        $searchform.=printSearchForm(DOL_URL_ROOT.'/user/index.php', DOL_URL_ROOT.'/user/index.php', $langs->trans("Users"), 'user', 'sall', 'M', 'searchleftuser', img_object('','user'));
     }
 }
 

+ 1 - 1
htdocs/install/mysql/migration/3.9.0-4.0.0.sql

@@ -335,7 +335,7 @@ CREATE TABLE llx_c_accounting_category (
   rowid 		integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
   code 			varchar(16) NOT NULL,
   label 		varchar(255) NOT NULL,
-  ranges 		varchar(255) NOT NULL,
+  range_account 		varchar(255) NOT NULL,
   position    	integer DEFAULT 0,
   fk_country 	integer DEFAULT NULL,			-- This category is dedicated to a country
   active 		integer DEFAULT 1

+ 1 - 1
htdocs/install/mysql/tables/llx_accounting_account.sql

@@ -29,7 +29,7 @@ create table llx_accounting_account
   pcg_type        			varchar(20)  NOT NULL,
   pcg_subtype     			varchar(20)  NOT NULL,
   account_number  			varchar(32)  NOT NULL,
-  account_parent  			varchar(32),
+  account_parent  			integer,							-- Hierarchic parent
   label           			varchar(255) NOT NULL,
   fk_accounting_category 	integer DEFAULT 0,
   fk_user_author  			integer DEFAULT NULL,

+ 1 - 1
htdocs/install/mysql/tables/llx_bordereau_cheque.key.sql

@@ -17,4 +17,4 @@
 -- ===========================================================================
 
 
-ALTER TABLE llx_bordereau_cheque ADD UNIQUE INDEX uk_bordereau_cheque (number, entity);
+ALTER TABLE llx_bordereau_cheque ADD UNIQUE INDEX uk_bordereau_cheque (ref, entity);

+ 3 - 3
htdocs/install/mysql/tables/llx_bordereau_cheque.sql

@@ -24,10 +24,10 @@
 create table llx_bordereau_cheque
 (
   rowid             integer AUTO_INCREMENT PRIMARY KEY,
-  number            varchar(16) NOT NULL,					-- ref
-  ref_ext	        varchar(255),							-- ref_ext
+  ref               varchar(30) NOT NULL,					-- ref
+  ref_ext	          varchar(255),							-- ref_ext
   datec             datetime NOT NULL,
-  date_bordereau    date,									-- A quoi sert cette date ?
+  date_bordereau    date,
   amount            double(24,8) NOT NULL,
   nbcheque          smallint NOT NULL,
   fk_bank_account   integer,

+ 1 - 1
htdocs/install/mysql/tables/llx_c_accounting_category.sql

@@ -21,7 +21,7 @@ CREATE TABLE llx_c_accounting_category (
   rowid 		integer NOT NULL AUTO_INCREMENT PRIMARY KEY,
   code 			varchar(16) NOT NULL,
   label 		varchar(255) NOT NULL,
-  ranges 		varchar(255) NOT NULL,
+  range_account 		varchar(255) NOT NULL,
   position    	integer DEFAULT 0,
   fk_country 	integer DEFAULT NULL,			-- This category is dedicated to a country
   active 		integer DEFAULT 1

+ 2 - 0
htdocs/langs/en_US/admin.lang

@@ -1610,6 +1610,8 @@ BankOrderGlobal=General
 BankOrderGlobalDesc=General display order
 BankOrderES=Spanish
 BankOrderESDesc=Spanish display order
+ChequeReceiptsNumberingModule=Cheque Receipts Numbering module
+
 ##### Multicompany #####
 MultiCompanySetup=Multi-company module setup
 ##### Suppliers #####

+ 2 - 2
htdocs/projet/class/task.class.php

@@ -588,7 +588,7 @@ class Task extends CommonObject
                 $sql.= ", ".MAIN_DB_PREFIX."element_contact as ec2";
                 $sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc2";
             }
-            $sql.= " WHERE p.entity = ".$conf->entity;
+            $sql.= " WHERE p.entity IN (".getEntity('project',1).")";
             $sql.= " AND t.fk_projet = p.rowid";
         }
         elseif ($mode == 1)
@@ -609,7 +609,7 @@ class Task extends CommonObject
             {
                 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t on t.fk_projet = p.rowid";
             }
-            $sql.= " WHERE p.entity = ".$conf->entity;
+            $sql.= " WHERE p.entity IN (".getEntity('project',1).")";
         }
         else return 'BadValueForParameterMode';
 

+ 1 - 1
htdocs/projet/contact.php

@@ -47,7 +47,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php';  // Must be inclu
 // Security check
 $socid=0;
 if ($user->societe_id > 0) $socid=$user->societe_id;
-$result = restrictedArea($user, 'projet', $id);
+$result = restrictedArea($user, 'projet', $id,'projet&project');
 
 
 /*

+ 1 - 1
htdocs/projet/document.php

@@ -43,7 +43,7 @@ $mine 		= (GETPOST('mode','alpha') == 'mine' ? 1 : 0);
 // Security check
 $socid=0;
 if ($user->societe_id > 0) $socid=$user->societe_id;
-$result=restrictedArea($user,'projet',$id,'');
+$result=restrictedArea($user,'projet',$id,'projet&project');
 
 $object = new Project($db);
 

+ 1 - 1
htdocs/projet/element.php

@@ -92,7 +92,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php';  // Must be inclu
 // Security check
 $socid=0;
 if ($user->societe_id > 0) $socid=$user->societe_id;
-$result = restrictedArea($user, 'projet', $projectid);
+$result = restrictedArea($user, 'projet', $projectid, 'projet&project');
 
 
 /*

+ 1 - 1
htdocs/projet/ganttview.php

@@ -44,7 +44,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php';  // Must be inclu
 // Security check
 $socid=0;
 if ($user->societe_id > 0) $socid=$user->societe_id;
-$result = restrictedArea($user, 'projet', $id);
+$result = restrictedArea($user, 'projet', $id,'projet&project');
 
 $langs->load("users");
 $langs->load("projects");

+ 1 - 1
htdocs/projet/note.php

@@ -42,7 +42,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php';  // Must be inclu
 // Security check
 $socid=0;
 if ($user->societe_id > 0) $socid=$user->societe_id;
-$result = restrictedArea($user, 'projet', $id);
+$result = restrictedArea($user, 'projet', $id,'projet&project');
 
 $permissionnote=$user->rights->projet->creer;	// Used by the include of actions_setnotes.inc.php
 

+ 1 - 1
htdocs/projet/tasks.php

@@ -61,7 +61,7 @@ $extralabels_task=$extrafields_task->fetch_name_optionals_label($taskstatic->tab
 // Security check
 $socid=0;
 if ($user->societe_id > 0) $socid = $user->societe_id;
-$result = restrictedArea($user, 'projet', $id);
+$result = restrictedArea($user, 'projet', $id,'projet&project');
 
 // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
 $hookmanager->initHooks(array('projecttaskcard','globalcard'));

+ 7 - 0
htdocs/projet/tasks/contact.php

@@ -492,6 +492,13 @@ if ($id > 0 || ! empty($ref))
 	}
 }
 
+if (is_object($hookmanager))
+{
+	$hookmanager->initHooks(array('contacttpl'));
+	$parameters=array();
+	$reshook=$hookmanager->executeHooks('formContactTpl',$parameters,$object,$action);
+}
+
 
 llxFooter();
 

+ 3 - 0
htdocs/theme/eldy/style.css.php

@@ -3880,6 +3880,9 @@ li.ui-li-divider .ui-link {
 a.ui-link, a.ui-link:hover, .ui-btn:hover, span.ui-btn-text:hover, span.ui-btn-inner:hover {
 	text-decoration: none !important;
 }
+.ui-body-c {
+	background: #fff;
+}
 
 .ui-btn-inner {
 	min-width: .4em;