Configure query for homepage record count badge

Wish to see a specific feature/change in future releases? Feel free to post it here, and if it gets enough "likes", we'd definitely include it in future releases!
Post Reply
User avatar
wsiconcrete
Posts: 18
Joined: 2015-04-27 16:39
Location: SC, USA

Configure query for homepage record count badge

Post by wsiconcrete » 2020-04-20 09:05

Forgive me if I missed this when searching the forums, but for my current project I have an "Orders" table that AG generates the link for on the homepage and I have chosen to "Show record count in homepage". However, these orders will have a status of "Complete" assigned as they are processed and I would like to filter that count to disregard those orders.

I found this topic (viewtopic.php?f=7&t=3474&hilit=homepage+count+badge) which would allow me to create a custom link and hide the AG generated link, and I may do that if there is not an easier solution to configure the query used to generate the record count. I considered creating a parallel orders table to dump completed orders into but (and I can't remember the issue I encountered) for some reason I abandoned that path. I may be better served to go back and solve whatever that issue was?

Thanks!
Brandon

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Configure query for homepage record count badge

Post by pbottcher » 2020-04-20 19:15

Hi,

I don't think you can "easily" change that.

I see couple options that you may consider:

- as you already saw, create a custom link and remove the original one and possibly rearange the display in the homepage

- replace the badge counter directly via hooks/header-extras.php by checking if you are on the homepage and replace the badge counter with the result of your query

- edit the home.php file and put a dedicated query for your orders table (drawback, this will be overwritten if you recreate your app)
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
wsiconcrete
Posts: 18
Joined: 2015-04-27 16:39
Location: SC, USA

Re: Configure query for homepage record count badge

Post by wsiconcrete » 2020-04-22 06:13

Thanks for the reply! Ended up just using the header-extras.php option. Even though there is only one badge and I already have customizations on the homepage think this makes most sense to avoid further modifications to homepage. Please correct me if this should be done differently, but the below worked for my setup:

Code: Select all

<!-- BEGIN adjust orders count on homepage //-->
<?php
$activeOrders = sqlValue("SELECT count(1) FROM orders WHERE status <> 'Complete' AND status <> 'Cancelled'");
?>
<script> 
jQuery(function () {
	$j('#orders-tile').find('.badge').text('<?php echo $activeOrders ?>');
})
</script>
<!-- END adjust orders count on homepage //-->
Brandon

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Configure query for homepage record count badge

Post by pbottcher » 2020-04-22 18:29

Hi,

great to see that you got it working. The solution is fine.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

Post Reply