Skip to content

Commit

Permalink
Enhance sorting of field for lists on field with several sort criterias
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Apr 28, 2018
1 parent 2241418 commit e72c2e6
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 31 deletions.
5 changes: 3 additions & 2 deletions htdocs/compta/bank/class/account.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,10 @@ function get_url($fk_bank='', $url_id='', $type='')
* @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)) {
Expand Down Expand Up @@ -447,7 +448,7 @@ function addline($date, $oper, $label, $amount, $num_chq, $categorie, User $user

$this->db->begin();

$datev = $date;
if (is_null($datev) || empty($datev)) $datev = $date;

$accline = new AccountLine($this->db);
$accline->datec = $now;
Expand Down
6 changes: 5 additions & 1 deletion htdocs/compta/salaries/class/paymentsalary.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,11 @@ function create($user)
-abs($this->amount),
$this->num_payment,
'',
$user
$user,
'',
'',
'',
$this->datev
);

// Update fk_bank into llx_paiement.
Expand Down
11 changes: 4 additions & 7 deletions htdocs/compta/salaries/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
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");
Expand All @@ -52,8 +49,8 @@
$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"];
Expand Down Expand Up @@ -208,7 +205,7 @@
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);
Expand Down
9 changes: 5 additions & 4 deletions htdocs/compta/salaries/stats/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
$startyear=$year-1;
$endyear=$year;


/*
* View
*/
Expand Down Expand Up @@ -231,11 +232,11 @@
print '<br><br>';

print '<table class="border" width="100%">';
print '<tr height="24">';
print '<tr>';
print '<td align="center">'.$langs->trans("Year").'</td>';
print '<td align="center">'.$langs->trans("Number").'</td>';
print '<td align="center">'.$langs->trans("AmountTotal").'</td>';
print '<td align="center">'.$langs->trans("AmountAverage").'</td>';
print '<td align="right">'.$langs->trans("Number").'</td>';
print '<td align="right">'.$langs->trans("AmountTotal").'</td>';
print '<td align="right">'.$langs->trans("AmountAverage").'</td>';
print '</tr>';

$oldyear=0;
Expand Down
4 changes: 2 additions & 2 deletions htdocs/core/db/DoliDB.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ function lastquery()
/**
* 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)
Expand Down
19 changes: 11 additions & 8 deletions htdocs/core/js/lib_foot.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,18 @@
/* 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 <a> 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 <a> 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";
Expand Down
29 changes: 22 additions & 7 deletions htdocs/core/lib/functions.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <thead><tr>, 2=To use with <div>
* @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.
Expand Down Expand Up @@ -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.= '<a class="reposition" href="'.$file.'?sortfield='.$field.'&sortorder=desc&begin='.$begin.$options.'">';
else $out.= '<a class="reposition" href="'.$file.'?sortfield='.$field.'&sortorder=asc&begin='.$begin.$options.'">';
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.= '<a class="reposition" href="'.$file.'?sortfield='.$sortfield.'&sortorder=desc&begin='.$begin.$options.'">';
else $out.= '<a class="reposition" href="'.$file.'?sortfield='.$sortfield.'&sortorder=asc&begin='.$begin.$options.'">';
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.= '<a class="reposition" href="'.$file.'?sortfield='.$field.'&sortorder='.$sortordertouseinlink.'&begin='.$begin.$options.'">';
}

if ($tooltip) $out.=$form->textwithpicto($langs->trans($name), $langs->trans($tooltip));
Expand Down

0 comments on commit e72c2e6

Please sign in to comment.