Hey Guys,
How can i place a custom field in the customers table?
i tried the code of line 19 but gave the following error :
Message: Undefined variable: custom_fields
Filename: views/partial_client_table.php
Line Number: 19
Thanks for the help
This is the code i have so far :
Aswel as my custom field settings in the app :
I believe it is because you are not specifying what group the Custom Field belongs to but I could be wrong - I had a similar issue and Kovah replied…
https://community2.invoiceplane.com/t/topic/4569/2?u=nmay1990
Hi ,
Thanks!
But i get the same error i added on line 19 in the picture.
<?php echo $custom_fields['client']['Passagier']; ?>
still gives me error :
Message: Undefined variable: custom_fields
Filename: views/partial_client_table.php
Line Number: 19
Aarion
July 29, 2017, 8:59am
4
Hi mate,
You are getting this error because there is no $custom_fields passed into this view.
A very quick and dirty solution would be like this just to see whats going under the hood.You may want to improve it:slight_smile:
in Mdl_clients.php modify default_select method like this;
public function default_select()
{
$this->db->select(
'SQL_CALC_FOUND_ROWS ' . $this->table . '.*, ip_client_custom.client_custom_fieldvalue,ip_custom_fields.custom_field_label,' .
'CONCAT(' . $this->table . '.client_name, " ", ' . $this->table . '.client_surname) as client_fullname'
, false)->join('ip_client_custom','ip_clients.client_id=ip_client_custom.client_id','left')
->join('ip_custom_fields','ip_client_custom.client_custom_fieldid=custom_field_id','left');
}
now $records array will contain the fields you need.
you may call it like in your partial_client_table.php
<?php echo $client->custom_field_label;?>
<?php echo client_custom_fieldvalue;?>
Again, this is not the best way to it but when you try it you’ll see how to fetch the needed elements.
Hi ,
Any better way of doing this?
i tried it i placed the code in Mdl_clients
but then it only shows the title of the custom field in the table instead of the value itself.
My custom field Label is “Passagier”
This is my mdl code:
My client screen :
Kovah
July 30, 2017, 8:29am
6
Custom fields are not supported in client tables.
Edit:
Use the custom field block from
// Determine if discounts should be displayed
$items = $CI->mdl_items->where('invoice_id', $invoice_id)->get()->result();
// Discount settings
$show_item_discounts = false;
foreach ($items as $item) {
if ($item->item_discount != '0.00') {
$show_item_discounts = true;
}
}
// Get all custom fields
$custom_fields = array(
'invoice' => $CI->mdl_custom_fields->get_values_for_fields('mdl_invoice_custom', $invoice->invoice_id),
'client' => $CI->mdl_custom_fields->get_values_for_fields('mdl_client_custom', $invoice->client_id),
'user' => $CI->mdl_custom_fields->get_values_for_fields('mdl_user_custom', $invoice->user_id),
);
if ($invoice->quote_id) {
$custom_fields['quote'] = $CI->mdl_custom_fields->get_values_for_fields('mdl_quote_custom', $invoice->quote_id);
}
in the corresponding client controller method status()
* @param int $page
*/
public function status($status = 'active', $page = 0)
{
if (is_numeric(array_search($status, array('active', 'inactive')))) {
$function = 'is_' . $status;
$this->mdl_clients->$function();
}
$this->mdl_clients->with_total_balance()->paginate(site_url('clients/status/' . $status), $page);
$clients = $this->mdl_clients->result();
$this->layout->set(
array(
'records' => $clients,
'filter_display' => true,
'filter_placeholder' => trans('filter_clients'),
'filter_method' => 'filter_clients'
)
);
You would have to loop trough all clients and get the fields for each client separately.
Hi Kovah,
Thanks for the info.
Can you help me do this? Just for one custom field.
If possible offcource.
Thanks
Kovah
July 30, 2017, 11:31am
8
Sorry but I have no time to work with any custom coding tasks.
Okay no problem.
I understand.
If anyone else could help.
All help would be welcome.
Kovah
July 30, 2017, 1:29pm
10
Aarion
July 30, 2017, 1:38pm
11
Webtica,
Can you also share you partial_client_table.php file screenshot. I think you are almost there:) let me see it
1 Like
Hey Aarion,
Here is my partial client table:
Thanks for the help already.
Kind regards
Dieter
Aarion
July 30, 2017, 1:51pm
13
Ok so on line 19 what does it print out if you use $client->client_custom_fieldvalue
instead of $custom_fields->Passagier
?
1 Like
Hey Aarion,
This is my partial client table view after i applied your code :
And the error:
Aarion
July 30, 2017, 3:19pm
15
Ok one last request then,
under application/modules/clients/controllers/Clients.php
you’ll see this line;
$this->load->model('mdl_clients');
after that line please add these two;
$this->load->model('custom_fields/mdl_custom_fields');
$this->load->model('custom_fields/mdl_client_custom');
and refresh the page. See if you get the values in the table. If not please backup your partials table and paste this code;
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th><?php _trans('active'); ?></th>
<th><?php _trans('client_name'); ?></th>
<th><?php _trans('email_address'); ?></th>
<th><?php _trans('phone_number'); ?></th>
<th class="amount"><?php _trans('balance'); ?></th>
<th><?php _trans('options'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($records as $client) : ?>
<?php var_dump($client);?>
<?php endforeach; ?>
</tbody>
</table>
This will show us whats inside $clients array
Hi Aarion,
Im going to test this now
One min.
Hi Aarion,
So this is what i did :
I pasted the first two codes here:
Then i refreshed the page everything still the same.
So i pasted the next code here:
and i got as result this ( the custom field passagier is not in the array it seems.) :
Thanks
Dieter
Aarion
July 30, 2017, 4:01pm
18
Btw, Mdl_clients.php still has the joins right? That’s strange. From your screenshot of Custom Fields, I understand you added a custom field called Passenger and it belongs to the customer. If that’s the case that should show up. Can you make sure Mdl_clients.php has the joins.
Sorry, What do you mean with joins? ( im not great in this PHP code stuff )
Yes i made a custom field called Passenger this is a screenshot of the custom field settings:
Sorry My bad.
The Mdl code did it
it works!
But now so for example if i would make another custom field for example in invoices.
How can i show that custom field in that invoice table? do i just do the same codes for invoices or how can i add more custom fields to tables later down the line?