Plugin or HAck it out?
-
I have a WordPress site with multiple users. I would like to have a plugin that acts as a invoicing system. Where I would have an hourly rate/wage attached to a users role or entered in a custom field attached to a users profile. Then the user could log in go to a page where they can fill out a form and place the number of hours worked and produce a invoice. Does anyone know of a plugin for this type of function? If there is not a plugin to achieve this anyone have any ideas of how I could achieve this?
-
I don’t know of any plugins like that, but I don’t pay much attention to what’s available, I typically custom code to meet my needs.
You pretty much have what’s required fully thought out, so it’s just a matter of putting it to code. Of course you can create a plugin to do this, but you can also do this by creating a child theme that extends your current theme. Custom forms are slightly easier to implement in child themes, but can be done in plugins as well.
Unless you have no need for the normal post type, you should probably create a custom “invoice” post type to contain invoicing information. The forms for entering hours would be custom page templates. I think the user’s rate is better maintained as profile data, though doing so through roles is certainly possible.
Hey bcworkz, The solution you offered is right up my alley of thinking. I have no idea of where to start with the process. I do have programming knowledge and I am willing to learn. I will look into child themes but I never worked with a child theme before. I was thinking of approaching this by customizing a invoice plugin that already exist. Is this a recommended way to start? I think I may need the normal post type as well because I post stories on the front end of the site. If you can give me another push in the right direction I would definitely appreciate it.
There’s nothing special about a child theme really, it’s just a particular structure for introducing your own code into WP. Your child theme can have the exact look and feel of the parent theme, though tweaking this will be easier now. The main reason for using a child theme instead of plugin is only because creating custom page templates is easier.
Otherwise, the coding is the same for child theme or plugin, organize it however it makes sense for you. Likewise, creating a custom post type for invoices is not a big deal, they are still posts, except logically separated from the normal WP posts. You pretty much query and run loops for invoices just as you would for WP posts.
You could adapt an existing invoice plugin to run as a child theme. Or you can leave it as a plugin, and setup your form pages in the child theme, all other code is in the plugin. The two become an interdependent set.
I personally would not adapt an existing plugin unless it was very close to meeting my needs and only needed some minor tweaks. This is mainly because I’ve always had trouble wrapping my head around the coding done by others. I’m much more comfortable starting with my own code that I fully understand.
That is not to say you should not learn from existing plugins and even use bits of code as needed. I usually only look to existing plugins when I can’t figure out how to do something on my own. Then such a plugin can be very educational.
Here are the tasks as I see them for your project. Create a bare minimum functionality of each task, just enough so the interactions between the elements can be made to work. Once the minimal elements are all working together, you can start building on that base to eventually arrive at a full fledged system.
1. Establish a user profile/meta value that contains their hourly rate. Add a field for this on the user profile page and define a callback to ‘user_update’ (? I think that’s the one ?) that takes that value and saves it in user meta.
2. Create an input form/page where users can enter their hours. The form must also handle it’s POSTs, possibly creating a new invoice from the information, or maybe updating an existing one.
3. Register a custom post type in which the invoicing data can be maintained. Most of it will end up in postmeta, so add custom fields for this or create metaboxes to ease the viewing/editing of data.
4. Create an invoice template to be used to display the actual invoice data.
Most importantly, have fun with this 🙂
Man the fun has already begun! Thanks for the support in this learning process. If I had only kept to what I originally set out to do years ago which is learning the in’s and out’s of php I would have been set. But I have to kind of brush up where I left off in my learning process of php while I try my hand at this system. Since we last spoke I have found a plugin that gets me half way there. I found a plugin call WP Timesheets which allows a user to post time entries. My only hold up with this is that it lacks alot of the functionality I need. However I have gotten a kick out of the coding process and have shocked myself at some of the things that I have been able to pull off thus far. I have updated the main structure to display User, Date, Job Title, Hourly Wage, Time In, Time Out, Hours, Total. The User grabs the display name, Job Title actually grabs the “User Role,” which I have custom roles for each job title, Hourly Wage I was able to pull this off with the Advance Custom Fields plugin. Once I created the field which was user_wage I was able to call it to the list with the Advance Custom Fields API. The “Time In” and “Time Out” fields I hate because it seems as though it only stands for one day. Meaning the entry would only be for one day of work. I’m kind of confused of how I’m going to carry on from here in terms of the time but like you said I’m just looking to get the bare bones in place then tweak from there. My challenge now is getting the “Hourly wage” to multiply by the “Hours” field I tried using a mathematical Operator for this and it did not work I guess because I’m asking the variables to pull the user_wage and not a real number. If you would like to see screenshots or if you can skype, facetime, teamviewr with me I do not mind and that would be awesome.
I’m happy you find this entertaining! It is at times extremely frustrating or rewarding. While I’m always happy to offer coding advice related to WP, I am personally not that interested in your project. Don’t be offended, it’s mainly a time management tactic on my part. Don’t get me wrong, I am thrilled you are proud of what you’ve achieved and wish to share. I just don’t have the time to dedicate the attention it deserves. Best wished to you though!
Hey bcworkz,
I understand that you do not have interest in my project but just wondering if you might know if there is a way to pull this off. I have a custom field that holds a dollar amount (Ex: 10.00). I can pull the dollar amount from a custom field with a variable that contains the amount (Ex: $myAmount = 10.00), is there a way through php to multiply the dollar amount held in this variable with a number entered in a “text” input field? (Ex: $myAmount = 10.00 $textField = 8.0 , $myAmount * $textField = $fieldTotal_1) I would like to add the product of field one with the product of two more fields that are also multiplied in the same way (Ex: $fieldTotal_1 + $fieldTotal_2 + $fieldTotal_3 = $overall_Total). I want to have all of these fields added together to produce a total (Ex: $overall_Total). I would like to echo these totals out on another page. Is something like this possible?
Oops, I didn’t read you previous post carefully enough, my apologies.
Yes! Mathematical calculations are totally possible. You practically wrote the code unknowingly yourself, except the “equals” assignment always comes first. The syntax is very similar for most modern programming languages. Write out your formula using the proper operators and parenthesis, the usual hierarchy of operations apply, but it’s best to explicitly use parenthesis to be safe. Something like this will do it:
$overall_Total = ($myAmount * $textField)+($myAmount1 * $textField1)+($myAmount2 * $textField2);PHP usually handles type conversion automatically, so a text field that appears to be numeric is converted to numeric as required, so this should yield the correct result:
$myAmount = 10.0; //floating point number $textField = "0.8"; //text $fieldTotal_1 = $myAmount * $textField; echo $fieldTotal_1; //should output "8.0" or equivalentSometimes you must explicitly type cast a text value for the math to work:
$fieldTotal_1 = $myAmount * (float) $textField;
The topic ‘Plugin or HAck it out?’ is closed to new replies.