o8oygil Posted June 27, 2020 Share Posted June 27, 2020 We use billable items to bill for certain remote hands operations that are not part of our standard tasks. But they default to 'don't invoice'. We wouldn't be adding them if we didn't want to invoice them would we? So how do we change the default action to something else, like 'add to next invoice'? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 27, 2020 Share Posted June 27, 2020 8 hours ago, o8oygil said: So how do we change the default action to something else, like 'add to next invoice'? you could use a basic action hook (create .php file in /includes/hooks and paste the code below into it) to change the choice... <?php # Billable Items Default Action Chooser Hook # Written by brian! add_hook("AdminAreaFooterOutput", 1, function($vars) { if ($vars['filename'] == "billableitems" && $_REQUEST['action'] == 'manage' && !$_REQUEST['id']) { return <<<EOF <script type="text/javascript"> $('input:radio[name="invoiceaction"][value="2"]').click(); </script> EOF; } }); the only part you might need to adjust is your choice of default action and their relevant values... 0 => Don't Invoice for Now 1 => Invoice on Next Cron Run 2 => Add to User's Next Invoice 3 => Invoice as Normal for Due Date 4 => Recur Every so the above hook is currently choosing to add the BI to the next invoice (2)... if you're editing an existing BI, then the hook won't change the default action, allowing the previously selected action to remain chosen. 0 Quote Link to comment Share on other sites More sharing options...
o8oygil Posted August 5, 2020 Author Share Posted August 5, 2020 @brian! Thanks! You're a genius! That looks perfect! I put that .php file in there though and it didn't work. I checked permissions and selinux contexts and those seemed fine. I restarted httpd thinking mayne these get cached somehow and that didn't help. Then I actually read the code and noticed that clientsbillableitems is the name of the php file in the browser when I'm adding a billable item, not just 'billableitems'. I made that string replacement, and IT WORKS!!!! Thank you a million times! I'm re-pasting below with my mods to help other users. If by chance, billableitems IS a valid name for this form in some versions, then let me know and I'll make it a logical OR in the code. <?php # Billable Items Default Action Chooser Hook # Written by brian! # Appreciated and updated by o8oygil # Choose from the below default actions: # 0 => Don't Invoice for Now # 1 => Invoice on Next Cron Run # 2 => Add to User's Next Invoice # 3 => Invoice as Normal for Due Date # 4 => Recur Every #Set the value= below to the number of your choice. add_hook("AdminAreaFooterOutput", 1, function($vars) { if ($vars['filename'] == "clientbillableitems" && $_REQUEST['action'] == 'manage' && !$_REQUEST['id']) { return <<<EOF <script type="text/javascript"> $('input:radio[name="invoiceaction"][value="2"]').click(); </script> EOF; } }); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 7, 2020 Share Posted August 7, 2020 On 05/08/2020 at 18:55, o8oygil said: I'm re-pasting below with my mods to help other users. If by chance, billableitems IS a valid name for this form in some versions, then let me know and I'll make it a logical OR in the code. it is - the if statement should be (if you aren't going to use in_array)... if (($vars['filename'] == "billableitems" || $vars['filename'] == "clientsbillableitems") && $_REQUEST['action'] == 'manage' && !$_REQUEST['id']) { the problem is there are two ways to create a billable item - from the admin menu, the link goes to billableitems.php (the original hook handles that); but if you're in the client summary page, you can use clientsbillableitems.php (your hook handles that) - with the above if statement, the hook should handle both. 🙂 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.