son Posted April 24, 2019 Share Posted April 24, 2019 The default sorting of invoices within /admin/invoices.php is by due date, which is confusing for my business. Is there a way to change the default sorting on page load to invoice #? There's also a distinction between visible invoice number and invoice $_GET['id'] which WHMCS doesn't seem to understand - I'm definitely trying to sort by visible invoice number only. Thank you! 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted April 24, 2019 Share Posted April 24, 2019 Don't think there is a built-in option for the default sort. Perhaps a javascript in an admin output hook that does the sorting call on page load would do the trick. The ID in the $_GET['id'] is the database id, where the visible ID is the one that can be reset and formatted for sequential invoices. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted April 25, 2019 Share Posted April 25, 2019 18 hours ago, son said: The default sorting of invoices within /admin/invoices.php is by due date, which is confusing for my business. Is there a way to change the default sorting on page load to invoice #? Doable with an action hook. 18 hours ago, son said: There's also a distinction between visible invoice number and invoice $_GET['id'] which WHMCS doesn't seem to understand - I'm definitely trying to sort by visible invoice number only. Not possible, you'll need to create a custom page to get this result. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 25, 2019 Share Posted April 25, 2019 20 hours ago, son said: The default sorting of invoices within /admin/invoices.php is by due date, which is confusing for my business. Is there a way to change the default sorting on page load to invoice #? another way would be to change the link in the admin menu to invoices.php?orderby=id - though i'd agree with Kian that hooking would be a better long-term solution. 20 hours ago, son said: There's also a distinction between visible invoice number and invoice $_GET['id'] which WHMCS doesn't seem to understand - I'm definitely trying to sort by visible invoice number only. if sorting by custom invoice number format (and not it's ID), then the above should work... if you were wanting to order by invoice ID using a similar method, best you could do would be to sort by invoice date (orderby=date). 0 Quote Link to comment Share on other sites More sharing options...
son Posted April 26, 2019 Author Share Posted April 26, 2019 I got it to this point so far: function admin_sort_invoices_by_id($vars){ $filename = $vars['filename']; $filter = $_GET['filter']; $action = $_GET['action']; if (($filter == "") && ($action == "") && ($filename == "invoices")) { $url = 'invoices.php?orderby=id'; header( 'Location: '.$url ); } } add_hook('AdminAreaPage', 1, "admin_sort_invoices_by_id"); Is there an asc/desc option that I'm missing? https://developers.whmcs.com/api-reference/getinvoices/ implies that adding &order=desc would work but I guess invoices.php is not relying on the API. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted April 28, 2019 Share Posted April 28, 2019 On 26/04/2019 at 17:24, son said: Is there an asc/desc option that I'm missing? not that i'm aware of (Kian might know different!) - orderby acts as a toggle... which is one of the reasons why I suggested putting the link in the menu (in case you need to press it twice to get the order you ideally want). On 26/04/2019 at 17:24, son said: implies that adding &order=desc would work but I guess invoices.php is not relying on the API. it doesn't. 🙂 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted April 28, 2019 Share Posted April 28, 2019 (edited) The guy responsible for column sorting is $_COOKIE['WHMCSSD'] that is a base64 encoded string of a json encoded object. In other words if you place this code inside your hook... <? echo '<pre>'; print_r(json_decode(base64_decode($_COOKIE['WHMCSSD']), true)); echo '</pre>'; die(); You'll get the following response: Array ( [invoices] => Array ( [orderby] => id [sort] => DESC ) ) I'm converting the object to an array just because I like it more. Anyway as soon as you open invoice.php this cookie is empty therefore the table assumes that you want to use the default sorting (Due Date DESC). Since you want to sort by ID DESC we could simply define this cookie exactly as we want. <? function admin_sort_invoices_by_id($vars) { // If current page is invoices and the cookie is still empty we define it if ($vars['filename'] == 'invoices' AND !$_COOKIE['WHMCSSD']) { setcookie('WHMCSSD', base64_encode(json_encode(array('invoices' => array('orderby' => 'id', 'sort' => 'DESC')))), time() + (86400 * 30), '/'); header('Location: invoices.php'); die(); } } add_hook('AdminAreaPage', 1, "admin_sort_invoices_by_id"); You can normally sort by other columns ASC/DESC. The only difference is that you are overriding default sorting. I tested it on one of my WHMCS and it works but I do a lot of mistakes so double-check it 😀 Edited April 28, 2019 by Kian 2 Quote Link to comment Share on other sites More sharing options...
son Posted May 2, 2019 Author Share Posted May 2, 2019 That is clever! I would not have picked up the base64_encode job. Thank you. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.