@@ -332,11 +332,35 @@ component displayname="sysadmin" output="false" {
332332
333333 local .entries = 10 ;
334334
335+ // Sorting logic dependent on arguments.sort
336+ switch (arguments .sort ){
337+ case " strCompanyName ASC" :
338+ local .orderClause = "
339+ CASE
340+ WHEN customers.strCompanyName IS NULL OR customers.strCompanyName = '' THEN 1
341+ ELSE 0
342+ END,
343+ customers.strCompanyName ASC" ;
344+ break ;
345+
346+ case " strCompanyName DESC" :
347+ local .orderClause = "
348+ CASE
349+ WHEN customers.strCompanyName IS NULL OR customers.strCompanyName = '' THEN 1
350+ ELSE 0
351+ END,
352+ customers.strCompanyName DESC" ;
353+ break ;
354+
355+ default :
356+ local .orderClause = arguments .sort ;
357+ }
358+
335359 local .qCustomers = queryExecute (
336360 options = {datasource = application .datasource },
337361 sql = "
338362 SELECT DISTINCT customers.intCustomerID, customers.strCompanyName, customers.strContactPerson,
339- customers.strCity, customers.strEmail, customers.strLogo, customers.strPhone
363+ customers.strCity, customers.strEmail, customers.strLogo, customers.strPhone, customers.dtmInsertDate
340364 FROM customers
341365
342366 INNER JOIN users
@@ -353,31 +377,58 @@ component displayname="sysadmin" output="false" {
353377 customers.strEmail
354378 )
355379 #arguments .search #
356- ORDER BY #arguments . sort #
380+ ORDER BY #local . orderClause #
357381 LIMIT #arguments .start #, #local .entries #
358382 "
359383 );
360384
361385 return local .qCustomers ;
386+
362387 }
363388
364389 public query function getCustomer (required numeric start , required string sort ){
365390
366391 local .entries = 10 ;
367392
393+ // Sorting logic dependent on arguments.sort
394+ switch (arguments .sort ){
395+ case " strCompanyName ASC" :
396+ local .orderClause = "
397+ CASE
398+ WHEN customers.strCompanyName IS NULL OR customers.strCompanyName = '' THEN 1
399+ ELSE 0
400+ END,
401+ customers.strCompanyName ASC" ;
402+ break ;
403+
404+ case " strCompanyName DESC" :
405+ local .orderClause = "
406+ CASE
407+ WHEN customers.strCompanyName IS NULL OR customers.strCompanyName = '' THEN 1
408+ ELSE 0
409+ END,
410+ customers.strCompanyName DESC" ;
411+ break ;
412+
413+ default :
414+ local .orderClause = arguments .sort ;
415+ }
416+
368417 local .qCustomers = queryExecute (
369418 options = {datasource = application .datasource },
370419 sql = "
371420 SELECT customers.*, countries.strCountryName
372421 FROM customers
373- LEFT JOIN countries ON countries.intCountryID = customers.intCountryID
422+ LEFT JOIN countries
423+ ON countries.intCountryID = customers.intCountryID
374424 WHERE customers.blnActive = 1
375- ORDER BY #arguments . sort #
425+ ORDER BY #local . orderClause #
376426 LIMIT #arguments .start #, #local .entries #
377427 "
378428 );
379429
380430 return local .qCustomers ;
431+
381432 }
382433
383434 public query function getTotalInvoicesSearch (required string search , required string term , required numeric start , required string status , required string sort ){
0 commit comments