Create counter in navigation bar

Hi,
I would like to create a counter/notification (like Facebook notifications counter by the globe or friend icons) in the navigation bar.
I would like the counter to count the number of invoices within a certain criteria (I know the if statement to handle this and the javascript to render it in the navigation bar).

My first thought was to use a process logic hook to do this, but don’t know how to count the number of records…how would I do this?

Also I would like it to happen even when not in that module, so would an application logic hook together with getBean achieve this?

Thanks.

This is an interesting idea and it just so happens that Id been thinking about something like this recently although I would suggest doing it a different way. I am going to something similar as part of a theme.

The way I would go about doing this is to customise the theme and place it in the navigation bar that way. You can use smarty code and php directly in {php} {/php} tags within the smarty tpl. You could then use the sugar bean framework to get the number of invoices within your criteria and display them.

The tpl file you want to look at is themes/Suite7/tpls/header.tpl as this contains the nav bar. However you would want to make the actual customisations in the custom themes folder: custom/themes/Suite7/tpls/header.tpl

Hope this is of help.

Thank you! Yes I managed to do it!!!
Was not hard!

I ended up using a SQL query instead of getBean which worked much better and used num_rows to count the number of rows returned. Also, by putting it directly in the header tpl and using echo, it rendered it no matter which page was loaded!

{php}$qi_enquiry = "SELECT id FROM aos_invoices WHERE status='1' AND deleted='0' AND assigned_user_id='".$current_user->id."' AND date_modified <= now() - INTERVAL 5 DAY;";
$ri_enquiry = $db->query($qi_enquiry, true,"Error reading tasks entry: ");
$vi_enquiry = $ri_enquiry->num_rows;{/php}
{php}if ($vi_job > 0) {echo '<span class="counter">';echo $vi_job;echo '</span>';}{/php}

I then used CSS padding and border radius to style it to appear as a neat white circle next to the navigation link.

1 Like

No probs, looks good :wink: