Jump to content

Setting Default Invoice Action on Billable Items


o8oygil

Recommended Posts

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'?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 1 month later...

@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;
	}    
});

 

Link to comment
Share on other sites

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. 🙂

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated