From e72c2e6a11961719e0f47e60a02d2b3ac1d223ff Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 28 Apr 2018 19:54:41 +0200 Subject: [PATCH] Enhance sorting of field for lists on field with several sort criterias --- htdocs/compta/bank/class/account.class.php | 5 ++-- .../salaries/class/paymentsalary.class.php | 6 +++- htdocs/compta/salaries/index.php | 11 +++---- htdocs/compta/salaries/stats/index.php | 9 +++--- htdocs/core/db/DoliDB.class.php | 4 +-- htdocs/core/js/lib_foot.js.php | 19 +++++++----- htdocs/core/lib/functions.lib.php | 29 ++++++++++++++----- 7 files changed, 52 insertions(+), 31 deletions(-) diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index c773ef242ad..d1fec4a5a6d 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -395,9 +395,10 @@ class Account extends CommonObject * @param string $emetteur Name of cheque writer * @param string $banque Bank of cheque writer * @param string $accountancycode When we record a free bank entry, we must provide accounting account if accountancy module is on. + * @param int $datevalue Date value * @return int Rowid of added entry, <0 if KO */ - function addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur='',$banque='', $accountancycode='') + function addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user, $emetteur='',$banque='', $accountancycode='', $datev=null) { // Deprecatîon warning if (is_numeric($oper)) { @@ -447,7 +448,7 @@ class Account extends CommonObject $this->db->begin(); - $datev = $date; + if (is_null($datev) || empty($datev)) $datev = $date; $accline = new AccountLine($this->db); $accline->datec = $now; diff --git a/htdocs/compta/salaries/class/paymentsalary.class.php b/htdocs/compta/salaries/class/paymentsalary.class.php index 71cfe997fe0..3a3f34b85b4 100644 --- a/htdocs/compta/salaries/class/paymentsalary.class.php +++ b/htdocs/compta/salaries/class/paymentsalary.class.php @@ -388,7 +388,11 @@ class PaymentSalary extends CommonObject -abs($this->amount), $this->num_payment, '', - $user + $user, + '', + '', + '', + $this->datev ); // Update fk_bank into llx_paiement. diff --git a/htdocs/compta/salaries/index.php b/htdocs/compta/salaries/index.php index b5cdbb11a82..a88ec8683a9 100644 --- a/htdocs/compta/salaries/index.php +++ b/htdocs/compta/salaries/index.php @@ -28,10 +28,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/salaries/class/paymentsalary.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php'; -$langs->load("compta"); -$langs->load("salaries"); -$langs->load("bills"); -$langs->load("hrm"); +$langs->loadLangs(array("compta","salaries","bills","hrm")); // Security check $socid = GETPOST("socid","int"); @@ -52,8 +49,8 @@ if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (! $sortfield) $sortfield="s.datep"; -if (! $sortorder) $sortorder="DESC"; +if (! $sortfield) $sortfield="s.datep,s.rowid"; +if (! $sortorder) $sortorder="DESC,DESC"; $optioncss = GETPOST('optioncss','alpha'); $filtre=$_GET["filtre"]; @@ -208,7 +205,7 @@ if ($result) print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"s.rowid","",$param,"",$sortfield,$sortorder); print_liste_field_titre("Employee",$_SERVER["PHP_SELF"],"u.rowid","",$param,"",$sortfield,$sortorder); print_liste_field_titre("Label",$_SERVER["PHP_SELF"],"s.label","",$param,'align="left"',$sortfield,$sortorder); - print_liste_field_titre("DatePayment",$_SERVER["PHP_SELF"],"s.datep","",$param,'align="center"',$sortfield,$sortorder); + print_liste_field_titre("DatePayment",$_SERVER["PHP_SELF"],"s.datep,s.rowid","",$param,'align="center"',$sortfield,$sortorder); print_liste_field_titre("PaymentMode",$_SERVER["PHP_SELF"],"type","",$param,'align="left"',$sortfield,$sortorder); if (! empty($conf->banque->enabled)) print_liste_field_titre("BankAccount",$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder); print_liste_field_titre("PayedByThisPayment",$_SERVER["PHP_SELF"],"s.amount","",$param,'align="right"',$sortfield,$sortorder); diff --git a/htdocs/compta/salaries/stats/index.php b/htdocs/compta/salaries/stats/index.php index 0ba0c29ea6f..dbaeab2b252 100644 --- a/htdocs/compta/salaries/stats/index.php +++ b/htdocs/compta/salaries/stats/index.php @@ -59,6 +59,7 @@ $year = GETPOST('year')>0?GETPOST('year'):$nowyear; $startyear=$year-1; $endyear=$year; + /* * View */ @@ -231,11 +232,11 @@ print ''; print '

'; print ''; -print ''; +print ''; print ''; -print ''; -print ''; -print ''; +print ''; +print ''; +print ''; print ''; $oldyear=0; diff --git a/htdocs/core/db/DoliDB.class.php b/htdocs/core/db/DoliDB.class.php index c349d35a16d..ecc27bf88dc 100644 --- a/htdocs/core/db/DoliDB.class.php +++ b/htdocs/core/db/DoliDB.class.php @@ -221,8 +221,8 @@ abstract class DoliDB implements Database /** * Define sort criteria of request * - * @param string $sortfield List of sort fields, separated by comma. Example: 't1.fielda, t2.fieldb' - * @param string $sortorder Sort order, separated by comma. Example: 'ASC, DESC'; + * @param string $sortfield List of sort fields, separated by comma. Example: 't1.fielda,t2.fieldb' + * @param string $sortorder Sort order, separated by comma. Example: 'ASC,DESC'; * @return string String to provide syntax of a sort sql string */ function order($sortfield=null,$sortorder=null) diff --git a/htdocs/core/js/lib_foot.js.php b/htdocs/core/js/lib_foot.js.php index 14e2c3f3dec..f93fa57923f 100644 --- a/htdocs/core/js/lib_foot.js.php +++ b/htdocs/core/js/lib_foot.js.php @@ -141,15 +141,18 @@ print ' /* Set handler to add page_y param on output (click on href links or submit button) */ jQuery(".reposition").click(function() { var page_y = $(document).scrollTop(); - if (this.href) + if (page_y > 0) { - this.href=this.href+\'&page_y=\'+page_y; - console.log("We click on tag with .reposition class. this.ref is now "+this.href); - } - else - { - console.log("We click on tag with .reposition class but element is not an html tag, so we try to update form field page_y with value "+page_y); - jQuery("input[type=hidden][name=page_y]").val(page_y); + if (this.href) + { + this.href=this.href+\'&page_y=\'+page_y; + console.log("We click on tag with .reposition class. this.ref is now "+this.href); + } + else + { + console.log("We click on tag with .reposition class but element is not an html tag, so we try to update form field page_y with value "+page_y); + jQuery("input[type=hidden][name=page_y]").val(page_y); + } } }); });'."\n"; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 347dd641552..2094cd10c5c 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3964,7 +3964,7 @@ function print_liste_field_titre($name, $file="", $field="", $begin="", $morepar * @param string $name Translation key of field * @param int $thead 0=To use with standard table format, 1=To use inside , 2=To use with
* @param string $file Url used when we click on sort picto - * @param string $field Field to use for new sorting. Empty if this field is not sortable. + * @param string $field Field to use for new sorting. Empty if this field is not sortable. Example "t.abc" or "t.abc,t.def" * @param string $begin ("" by defaut) * @param string $moreparam Add more parameters on sort url links ("" by default) * @param string $moreattrib Add more attributes on th ("" by defaut, example: 'align="center"'). To add more css class, use param $prefix. @@ -4005,16 +4005,31 @@ function getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $m $options=preg_replace('/&+/i','&',$options); if (! preg_match('/^&/',$options)) $options='&'.$options; - if ($field1 != $sortfield1) // We are on another field + $sortordertouseinlink=''; + if ($field1 != $sortfield1) // We are on another field than current sorted field { - if (preg_match('/^DESC/', $sortorder)) $out.= ''; - else $out.= ''; + if (preg_match('/^DESC/i', $sortorder)) + { + $sortordertouseinlink.=str_repeat('desc,', count(explode(',',$field))); + } + else // We reverse the var $sortordertouseinlink + { + $sortordertouseinlink.=str_repeat('asc,', count(explode(',',$field))); + } } - else // We are of first sorting criteria + else // We are on field that is the first current sorting criteria { - if (preg_match('/^ASC/', $sortorder)) $out.= ''; - else $out.= ''; + if (preg_match('/^ASC/i', $sortorder)) // We reverse the var $sortordertouseinlink + { + $sortordertouseinlink.=str_repeat('desc,', count(explode(',',$field))); + } + else + { + $sortordertouseinlink.=str_repeat('asc,', count(explode(',',$field))); + } } + $sortordertouseinlink=preg_replace('/,$/', '', $sortordertouseinlink); + $out.= ''; } if ($tooltip) $out.=$form->textwithpicto($langs->trans($name), $langs->trans($tooltip));
'.$langs->trans("Year").''.$langs->trans("Number").''.$langs->trans("AmountTotal").''.$langs->trans("AmountAverage").''.$langs->trans("Number").''.$langs->trans("AmountTotal").''.$langs->trans("AmountAverage").'