Show Custom Field on a few pages

So I have a custom field “Customer No” added to client module. This is very important field for my business and every client is assign this unique number.

I would like to see this “Customer No” when I am viewing the list of the clients, viewing list of quotes and invoices. Also would like this number to be automatically imported into quotes and invoices when I select a client. Example: creating or editing invoice I should see “Customer No” underneath client’s phone/email. This number should be read only inside quotes and invoices but editable inside Clients module. I will create a few screenshots to help understanding what I am trying to achieve.

1 Like

It is a very good feature request.

Ah, a screenshot would help.
I think that you mean when you start searching for that client, that the customer gets shown in that tiny select list as well, next to the customer’s name.

Would you want this Customer number as a regular field in the Client’s screen at some point, instead of a custom field?

Do you want hints to develop it yourself or do you want to hope for the community to develop it?

It would be nice to search for client using customer number instead of name or maybe have both search fields (name and/or customer number). I have uploaded a few screenshots.

I can probably do it my self if someone can guide me. Community development would also be great for future release.

1 Like

That’s really appreciated. Let me find those solutions for you. Will probably be this weekend.

And thr customer number, would you mind it having it in the normal clients table instead of in the custom_fields?

The reason why i ask is:
With custom fields, you have to make an extra join whenever you want that field.
For example:
Clients index: select field, field, field from clients.
Ah, i want my custom field.
select field, field, field from clients LEFT JOIN custom_fields on ....
(and that for all those places where you want that customer number)

I think it would be better in normal clients table instead of custom_fields.

Thanks, I will forward github username once I remember :frowning:

1 Like

All files we’re going to add and edit are in the application directory.
Most of them are in /modules/clients.
If they are in different directory, i’ll say full path, otherwise, i’ll just talk about Controllers, Models, Views in that clients directory.


So … first task is to add your field to the database.
We use .sql files in /modules/setup/sql.
copy/paste that latest file and just add 1 to the filename:
038_1.6.2.sql, something like that.

When i add an important field, i’ll usually add it close to the client_id.
So maybe something like:
ALTER TABLE `ip_clients` ADD client_number VARCHAR(255) NULL DEFAULT NULL AFTER `client_id`;

Second task is to alter the functions.
Index of clients is in the Clients controller: Clients.php and then the index() function (status() function).
The view is in the views directory.

When the sql is not inside status() function, it’s inside the model.
For every place you want your field, just adjust the sql in the model and after that adjust your view: application/modules/clients/views/partial_client_table.php
I hope it makes sense.

Adding, Editing

Then the Ajax for the forms. They go through the Ajax controller.

Right now, this is the response for the frontend:

$response[] = [
                'id' => $client->client_id,
                'text' => (format_client($client)),

IF you’re adding extra stuff here, it will help you in the frontend.

If the sql says something like this: ```
$clients = $this->mdl_clients
->where(‘client_active’, 1)

it will get all fields, so your client_number will be in there.

## Saving
Saving the clients will get you by the `public function validation_rules()` in the model, so add your rule for the client_number.
I would still validate on a string, so users can add their own variations.

## Invoices
Models, Views, Controllers in the `application/modules/invoices` directory

## Reports
Models, Views, Controllers in the 
`application/modules/reports` directory

## Quotes, Projects, etc
Let's say they want to search for a client or 'change_client': `site_url('quotes/ajax/modal_change_client')`
Then you'll goto the `Quotes` module, the `Ajax` controller, the `modal_change_client` function

Try to go over every place where clients are chosen and shown.
Even if you don't use tasks or something like that, try to change it there as well.

Go slow, make your preferred change first, then add the rest.

Hope it helps!

2 posts were split to a new topic: Question about invoice_quote_number

I solved client_number and works great. Then I added more fields in quotes and invoices. Yes please, split it from original question. Thanks! I have created a pull request with all changes that I made. Again thank you.

1 Like