diff --git a/htdocs/accountancy/class/html.formventilation.class.php b/htdocs/accountancy/class/html.formventilation.class.php
index e479b5931be..069e0ea3df3 100644
--- a/htdocs/accountancy/class/html.formventilation.class.php
+++ b/htdocs/accountancy/class/html.formventilation.class.php
@@ -30,6 +30,10 @@
*/
class FormVentilation extends Form
{
+
+ private $options_cache = array();
+
+
/**
* Return select filter with date of transaction
*
@@ -70,63 +74,76 @@ class FormVentilation extends Form
* @param int $select_in selectid value is a aa.rowid (0 default) or aa.account_number (1)
* @param int $select_out set value returned by select 0=rowid (default), 1=account_number
* @param string $morecss More css non HTML object
- * @return string String with HTML select
+ * @param string $usecache Key to use to store result into a cache. Next call with same key will reuse the cache.
+ * @return string String with HTML select
*/
- function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone') {
+ function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='')
+ {
global $conf;
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
- $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT') ? $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT : 50;
-
- $sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version";
- $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 asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
- $sql .= " AND aa.active = 1";
- $sql .= " ORDER BY aa.account_number";
-
- dol_syslog(get_class($this) . "::select_account", LOG_DEBUG);
- $resql = $this->db->query($sql);
-
- if (!$resql) {
- $this->error = "Error " . $this->db->lasterror();
- dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR);
- return -1;
- }
-
- $out = ajax_combobox($htmlname, $event);
-
- // TODO Add $options in cache so next call will not execute the request
- $selected = 0;
- $options = array();
- while ($obj = $this->db->fetch_object($resql))
+ $options = array();
+ if ($usecache && ! empty($this->options_cache[$usecache]))
{
- $label = length_accountg($obj->account_number) . ' - ' . $obj->label;
- $label = dol_trunc($label, $trunclength);
-
- $select_value_in = $obj->rowid;
- $select_value_out = $obj->rowid;
-
- // Try to guess if we have found default value
- if ($select_in == 1) {
- $select_value_in = $obj->account_number;
- }
- if ($select_out == 1) {
- $select_value_out = $obj->account_number;
- }
- // Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number
- // Because same account_number can be share between different accounting_system and do have the same meaning
- if ($selectid != '' && $selectid == $select_value_in) {
- //var_dump("Found ".$selectid." ".$select_value_in);
- $selected = $select_value_out;
- }
-
- $options[$select_value_out] = $label;
+ $options = $this->options_cache[$usecache];
}
+ else
+ {
+ $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT') ? $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT : 50;
+
+ $sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version";
+ $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 asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
+ $sql .= " AND aa.active = 1";
+ $sql .= " ORDER BY aa.account_number";
+
+ dol_syslog(get_class($this) . "::select_account", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+
+ if (!$resql) {
+ $this->error = "Error " . $this->db->lasterror();
+ dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR);
+ return -1;
+ }
+ $out = ajax_combobox($htmlname, $event);
+
+ $selected = 0;
+ while ($obj = $this->db->fetch_object($resql))
+ {
+ $label = length_accountg($obj->account_number) . ' - ' . $obj->label;
+ $label = dol_trunc($label, $trunclength);
+
+ $select_value_in = $obj->rowid;
+ $select_value_out = $obj->rowid;
+
+ // Try to guess if we have found default value
+ if ($select_in == 1) {
+ $select_value_in = $obj->account_number;
+ }
+ if ($select_out == 1) {
+ $select_value_out = $obj->account_number;
+ }
+ // Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number
+ // Because same account_number can be share between different accounting_system and do have the same meaning
+ if ($selectid != '' && $selectid == $select_value_in) {
+ //var_dump("Found ".$selectid." ".$select_value_in);
+ $selected = $select_value_out;
+ }
+
+ $options[$select_value_out] = $label;
+ }
+ $this->db->free($resql);
+
+ if ($usecache)
+ {
+ $this->options_cache[$usecache] = $options;
+ }
+ }
+
$out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
- $this->db->free($resql);
return $out;
}
diff --git a/htdocs/accountancy/customer/lines.php b/htdocs/accountancy/customer/lines.php
index 2e3bdf6b6fc..71f52ec48a7 100644
--- a/htdocs/accountancy/customer/lines.php
+++ b/htdocs/accountancy/customer/lines.php
@@ -263,7 +263,7 @@ if ($result) {
print_liste_field_titre($langs->trans("Description"), $_SERVER["PHP_SELF"], "fd.description", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre($langs->trans("Amount"), $_SERVER["PHP_SELF"], "fd.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
print_liste_field_titre($langs->trans("VATRate"), $_SERVER["PHP_SELF"], "fd.tva_tx", "", $param, 'align="center"', $sortfield, $sortorder);
- print_liste_field_titre($langs->trans("Account"), $_SERVER["PHP_SELF"], "aa.account_number", "", $param, 'align="center"', $sortfield, $sortorder);
+ print_liste_field_titre($langs->trans("Account"), $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre($langs->trans("Country"), $_SERVER["PHP_SELF"], "co.label", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre($langs->trans("VATIntra"), $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre('', '', '', '', '', 'align="center"');
@@ -278,7 +278,7 @@ if ($result) {
print '
';
print ' ';
print ' ';
- print ' ';
+ print ' ';
print ' ';
print ' ';
print '';
@@ -309,7 +309,7 @@ if ($result) {
// Ref Invoice
print ' ' . $facture_static->getNomUrl(1) . ' ';
- print '' . dol_print_date($objp->datef, 'day') . ' ';
+ print '' . dol_print_date($db->jdate($objp->datef), 'day') . ' ';
// Ref Product
print '';
@@ -318,12 +318,19 @@ if ($result) {
if ($objp->product_label) print ' '.$objp->product_label;
print ' ';
- print '' . nl2br(dol_trunc($objp->description, 32)) . ' ';
+ print '';
+ $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
+ $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION') ? ACCOUNTING_LENGTH_DESCRIPTION : 32;
+ print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->description);
+ print ' ';
+
print '' . price($objp->total_ht) . ' ';
print '' . price($objp->tva_tx) . ' ';
- print '' . $codecompta . '';
+ print ' ';
+ print $codecompta . ' ';
print img_edit();
- print ' ';
+ print '';
+ print '';
print '' . $objp->country .' ';
print '' . $objp->tva_intra . ' ';
print ' ';
diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php
index 94d68544c72..aa1c2742a08 100644
--- a/htdocs/accountancy/customer/list.php
+++ b/htdocs/accountancy/customer/list.php
@@ -287,6 +287,10 @@ if ($result) {
$product_static->id = $objp->product_id;
$product_static->type = $objp->type;
$product_static->label = $objp->product_label;
+
+ $facture_static->ref = $objp->facnumber;
+ $facture_static->id = $objp->facid;
+ $facture_static->type = $objp->ftype;
$code_sell_p_notset = '';
$objp->aarowid_suggest = $objp->aarowid;
@@ -320,12 +324,9 @@ if ($result) {
print '' . $objp->rowid . ' ';
// Ref Invoice
- $facture_static->ref = $objp->facnumber;
- $facture_static->id = $objp->facid;
- $facture_static->type = $objp->ftype;
print '' . $facture_static->getNomUrl(1) . ' ';
- print '' . dol_print_date($objp->datef, 'day') . ' ';
+ print '' . dol_print_date($db->jdate($objp->datef), 'day') . ' ';
// Ref Product
print '';
@@ -334,9 +335,11 @@ if ($result) {
if ($objp->product_label) print ' '.$objp->product_label;
print ' ';
-
+ print '';
+ $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
$trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION') ? ACCOUNTING_LENGTH_DESCRIPTION : 32;
- print ' ' . nl2br(dol_trunc($objp->description, $trunclength)) . ' ';
+ print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->description);
+ print '';
print '';
print price($objp->total_ht);
@@ -360,7 +363,7 @@ if ($result) {
print ' ';
print '';
- print $formventilation->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1);
+ print $formventilation->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone', 'cachewithshowemptyone');
print ' ';
print '';
diff --git a/htdocs/accountancy/expensereport/lines.php b/htdocs/accountancy/expensereport/lines.php
index d42ee8442ed..29a8b167b87 100644
--- a/htdocs/accountancy/expensereport/lines.php
+++ b/htdocs/accountancy/expensereport/lines.php
@@ -279,12 +279,15 @@ if ($result) {
// Ref Invoice
print ' ' . $expensereport_static->getNomUrl(1) . ' ';
- print '' . dol_print_date($objp->date, 'day') . ' ';
+ print '' . dol_print_date($db->jdate($objp->date), 'day') . ' ';
print '' . $objp->fees_label . ' ';
+ print '';
+ $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->comments));
$trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION') ? ACCOUNTING_LENGTH_DESCRIPTION : 32;
- print ' ' . nl2br(dol_trunc($objp->comments, $trunclength)) . ' ';
+ print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->comments);
+ print '';
print '' . price($objp->total_ht) . ' ';
diff --git a/htdocs/accountancy/expensereport/list.php b/htdocs/accountancy/expensereport/list.php
index 103dd7f98d3..ef7acac9ad0 100644
--- a/htdocs/accountancy/expensereport/list.php
+++ b/htdocs/accountancy/expensereport/list.php
@@ -282,7 +282,7 @@ if ($result) {
// Line id
print '' . $objp->rowid . ' ';
- print '' . dol_print_date($objp->date, 'day') . ' ';
+ print '' . dol_print_date($db->jdate($objp->date), 'day') . ' ';
// Ref Expense report
print '' . $expensereport_static->getNomUrl(1) . ' ';
@@ -293,9 +293,11 @@ if ($result) {
print '';
// Fees description -- Can be null
- // TODO: we should set a user defined value to adjust user square / wide screen size
+ print '';
+ $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->comments));
$trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION') ? ACCOUNTING_LENGTH_DESCRIPTION : 32;
- print ' ' . nl2br(dol_trunc($objp->comments, $trunclength)) . ' ';
+ print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->comments);
+ print '';
print '';
print price($objp->price);
@@ -313,7 +315,7 @@ if ($result) {
// Colonne choix du compte
print ' ';
- print $formventilation->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1);
+ print $formventilation->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone', 'cachewithshowemptyone');
print ' ';
// Colonne choix ligne a ventiler
diff --git a/htdocs/accountancy/supplier/lines.php b/htdocs/accountancy/supplier/lines.php
index 7b5e3bd7f24..a2cdc7b42cc 100644
--- a/htdocs/accountancy/supplier/lines.php
+++ b/htdocs/accountancy/supplier/lines.php
@@ -248,8 +248,7 @@ if ($result) {
print_liste_field_titre($langs->trans("Description"), $_SERVER["PHP_SELF"], "l.description", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre($langs->trans("Amount"), $_SERVER["PHP_SELF"], "l.total_ht", "", $param, 'align="right"', $sortfield, $sortorder);
print_liste_field_titre($langs->trans("VATRate"), $_SERVER["PHP_SELF"], "l.tva_tx", "", $param, 'align="center"', $sortfield, $sortorder);
- print_liste_field_titre($langs->trans("Account"), $_SERVER["PHP_SELF"], "aa.account_number", "", $param, 'align="center"', $sortfield, $sortorder);
- print_liste_field_titre('');
+ print_liste_field_titre($langs->trans("Account"), $_SERVER["PHP_SELF"], "aa.account_number", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre('', '', '', '', '', 'align="center"');
print "\n";
@@ -263,8 +262,7 @@ if ($result) {
print ' ';
print ' ';
print ' ';
- print ' ';
- print ' ';
+ print ' ';
print '';
$searchpitco=$form->showFilterAndCheckAddButtons(1);
print $searchpitco;
@@ -278,7 +276,7 @@ if ($result) {
while ( $i < min($num_lines, $limit) ) {
$objp = $db->fetch_object($result);
$var = ! $var;
- $codeCompta = length_accountg($objp->account_number) . ' - ' . $objp->label;
+ $codecompta = length_accountg($objp->account_number) . ' - ' . $objp->label;
$facturefournisseur_static->ref = $objp->facnumber;
$facturefournisseur_static->id = $objp->facid;
@@ -299,7 +297,7 @@ if ($result) {
print $objp->invoice_label;
print ' ';
- print '' . dol_print_date($objp->datef, 'day') . ' ';
+ print '' . dol_print_date($db->jdate($objp->datef), 'day') . ' ';
// Ref Product
print '';
@@ -308,11 +306,16 @@ if ($result) {
if ($objp->product_label) print ' '.$objp->product_label;
print ' ';
- print '' . nl2br(dol_trunc($objp->description, 32)) . ' ';
+ print '';
+ $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
+ $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION') ? ACCOUNTING_LENGTH_DESCRIPTION : 32;
+ print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->description);
+ print ' ';
+
print '' . price($objp->total_ht) . ' ';
print '' . price($objp->tva_tx) . ' ';
- print '' . $codeCompta . ' ';
- print '';
+ print ' ';
+ print $codecompta . ' ';
print img_edit();
print ' ';
diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php
index 47510b98b2b..e59fb91cf23 100644
--- a/htdocs/accountancy/supplier/list.php
+++ b/htdocs/accountancy/supplier/list.php
@@ -300,6 +300,7 @@ if ($result) {
$facturefourn_static->ref = $objp->ref;
$facturefourn_static->id = $objp->facid;
+ $facturefourn_static->type = $objp->type;
$code_buy_p_notset = '';
$objp->aarowid_suggest = $objp->aarowid;
@@ -337,7 +338,7 @@ if ($result) {
print $objp->invoice_label;
print '';
- print '' . dol_print_date($objp->datef, 'day') . ' ';
+ print '' . dol_print_date($db->jdate($objp->datef), 'day') . ' ';
// Ref product
print '';
@@ -346,9 +347,12 @@ if ($result) {
if ($objp->product_label) print ' '.$objp->product_label;
print ' ';
- // TODO: we should set a user defined value to adjust user square / wide screen size
+ // Description
+ print '';
+ $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description));
$trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION') ? ACCOUNTING_LENGTH_DESCRIPTION : 32;
- print ' ' . nl2br(dol_trunc($objp->description, $trunclength)) . ' ';
+ print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->description);
+ print '';
print '';
print price($objp->price);
@@ -373,7 +377,7 @@ if ($result) {
// Suggested accounting account
print ' ';
- print $formventilation->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1);
+ print $formventilation->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone', 'cachewithshowemptyone');
print ' ';
// Colonne choix ligne a ventiler
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index db1d70b4899..4f68b32f171 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -619,17 +619,18 @@ function dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
* Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
*
* @param string $stringtoescape String to escape
- * @param int $keepb Do not clean b tags
+ * @param int $keepb 1=Preserve b tags (otherwise, remove them)
+ * @param int $keepn 1=Preserve \r\n strings (otherwise, remove them)
* @return string Escaped string
*
* @see dol_string_nohtmltag
*/
-function dol_escape_htmltag($stringtoescape,$keepb=0)
+function dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
{
// escape quotes and backslashes, newlines, etc.
$tmp=dol_html_entity_decode($stringtoescape,ENT_COMPAT,'UTF-8');
- if ($keepb) $tmp=strtr($tmp, array("\r"=>'\\r',"\n"=>'\\n'));
- else $tmp=strtr($tmp, array("\r"=>'\\r',"\n"=>'\\n',""=>'',' '=>''));
+ if (! $keepb) $tmp=strtr($tmp, array(""=>'',' '=>''));
+ if (! $keepn) $tmp=strtr($tmp, array("\r"=>'\\r',"\n"=>'\\n'));
return dol_htmlentities($tmp,ENT_COMPAT,'UTF-8');
}
@@ -4395,7 +4396,7 @@ function picto_required()
* Clean a string from all HTML tags and entities
*
* @param string $StringHtml String to clean
- * @param integer $removelinefeed 1=Replace also all lines feeds by a space, 0=Only last one are removed
+ * @param integer $removelinefeed 1=Replace also new lines by a space, 0=Only last one are removed
* @param string $pagecodeto Encoding of input/output string
* @return string String cleaned
*
@@ -4404,6 +4405,7 @@ function picto_required()
function dol_string_nohtmltag($StringHtml,$removelinefeed=1,$pagecodeto='UTF-8')
{
$pattern = "/<[^<>]+>/";
+ $StringHtml = preg_replace('/ ]*>/', "\n", $StringHtml);
$temp = dol_html_entity_decode($StringHtml,ENT_COMPAT,$pagecodeto);
$temp = preg_replace($pattern,"",$temp);
@@ -4425,7 +4427,7 @@ function dol_string_nohtmltag($StringHtml,$removelinefeed=1,$pagecodeto='UTF-8')
*
* @param string $text Input text
* @return string Output text
- * @see dol_nboflines_bis
+ * @see dol_nboflines_bis, dol_string_nohtmltag, dol_escape_htmltag
*/
function dolGetFirstLineOfText($text)
{
diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php
index f967b53d9db..786970e2b3a 100644
--- a/test/phpunit/FunctionsLibTest.php
+++ b/test/phpunit/FunctionsLibTest.php
@@ -367,6 +367,14 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase
$after=dol_string_nohtmltag($text, 1);
$this->assertEquals("A string with tag with < chars",$after,"test3");
+ $text="A string Another string";
+ $after=dol_string_nohtmltag($text,0);
+ $this->assertEquals("A string\nAnother string",$after,"test4");
+
+ $text="A string Another string";
+ $after=dol_string_nohtmltag($text,1);
+ $this->assertEquals("A string Another string",$after,"test5");
+
return true;
}