Skip to content

Centralize the contact name concat sql code

We have this pattern to concat the contact name together 38 times in the codebase! Making for long and hard to read SQL queries...

CONCAT(IF(client.company_name != '', CONCAT(client.company_name, ' :: '), ''), client.contact_name, ' (', client.username, IF(client.customer_no != '', CONCAT(', ', client.customer_no), ''), ')')

And we have subtle variations making it probably 46 times in total.

Lets replace that with a central definition to make these queries more readable. We could use a $conf var defined in config.inc.php... giving the additional benefit of being able to customize the format.

I've taken the opportunity to wrap the remaining sql query over multiple lines to further improve the readability.

I'm open to discuss the code style of this and where we store the pattern ... just hoping to improve the readability overall and reduce duplication.

Edited by Helmo

Merge request reports