# cdnpayroll.py Payroll calculations for Canada
Sat Dec 31 17:48:33 2005 <pevans@catholic.org> The 2006 version of cdnpayroll.py should just run straight from the command line no matter where you put it, assuming you have a python interpreter on your system of course. This release contains all the modules and functions in a single python file:
- Because after 6 years of waiting, I've pretty much given up on anyone maintaining a province and
- It's just easier for people to run
2006 also brings html input and output. This has been tested for a few months now and seems fine with no reported bugs. You should set the 'home' variable near the beginning of the script to match your website (the default is 'localhost'). 'payform.html' is set to call /cgi-bin/cdnpayroll.py already and should be placed in server-root of your site.
The kaptain binary is unchanged and still included in the tarball. It hasn't been recompiled, but it runs fine on my 64-bit and 32-bit Mandriva Linux systems, so it should be fine for others too. The .kaptn script itself is also included as before.
Hard to believe a year has gone by since I wanted to do a Kommander version. Unfortunately, the year went fast for Eric L and the gang too and hklibs haven't been added yet, so no database integration there :-( yet anyhow. I'll do it when they do it.
WebERP continues to improve steadily and that's probably what I'll use myself next.
Wed Jun 13 12:22:47 PM PDT 2001 <pevans@users.sf.net>
0.90
- Made required changes for AB, MB, SK and ON
- Cleaned up kaptain gui a bit, added tables and news
- Note that --spread now takes an argument for file name
- If no Gross Income is entered, the rates/hrs will be used
# Sat Apr 28 11:50:57 AM PDT 2001 Paul Evans <pevans@users.sourceforge.net> # 0.82 added spreadsheet option (--spread)
Using --spread <filename> produces a csv file by that name, if it doesn't exist. If it does exist, a new row will be inserted below the existing entries. payroll.csv contains a label row at the top and a totals row with sums at the bottom. StarOffice reads these files directly and the defaults listed in it's import dialog are fine - just click 'O.K.' to it. For Gnumeric you need to use the import item on it's file menu.Most spreadsheet programs will read a csv file.
I've added a checkbox, so that you can now append the save file. I was just adding a '>' to the filename before to achieve the same thing. Not very obvious I know.
Original Readme
cdnpayroll was written to address my own need, but in the hope that others might find it usefull as a sort of plug-in to some larger work (as I do). If nothing else, it's good for a variable list.
It has been tested against the MSW.exe from the Canadian government and the largest error seen was $0.05. Usually, any error is one or two cents. Not all combinations and ranges have been tested of course, so please run a few for your own situation before trusting your employee's paydays to it.
cdnpayroll will accept as few, or as many arguments as you need to define a paycheque. In addition, you can edit the main cdnpayroll.py file and hardcode some in to simplify things. Holiday pay, WCB, RESIDEnce etc. are good candidates for this approach.
All the individual provincial calculations are broken out into separate modules, because in addition to the (at least) twice a year the feds will change, who knows what will happen with provincial elections, budget speeches etc. Also, it's easier for others to focus on their own province/territory. You are encouraged to 'adopt' a provincial module for maint. A Quebec one would be especially nice given the different laws and (in particualar) the part about tips and gratuities...
I just picked up python a few weeks ago (I was going to do this in perl), so go easy on me when reading it, but please do feel free to point out my un-pythonesque writing - it's my first foray into OO as well. The first thing I wrote with python used wxwindows and seemingly every module under the sun, but I've intentionally tried to keep cdnpayroll minimal that way.
The following is just a copy of the '-h' switch:
Usage: [python] cdnpayroll.py -f [-p] [-P]-r -i [other args]
[python] cdnpayroll.py -h (or --help) is this help message.
Many arguments have both a long and a short form. The above shown are a minimal subset, but quite often sufficient. All the amount variables found in T4127(E) are listed below. The order doesn't matter.
- Where
- -f, --td1f is the employee's Federal Claim Code (e.g. -f 2 or --td1f 2)
-p, --td1p is the employee's Federal Claim Code (e.g. -p 2 or --td1p 2)
-r, --resides is the province of residence for tax purposes. default: BC
One of:
'AB':'Alberta', 'BC':'British Columbia', 'MB':'Manitoba', 'NB':'New Brunswick', 'NF':'Newfoundland', 'NT':'Northwest Territories', 'NS':'Nova Scotia', 'NU':'Nunavoot', 'ON':'Ontario', 'PE':'Prince Edward Island', 'QC':'Quebec', 'SK':'Saskatchewan', 'YT':'Yukon', 'OT':'Outside' (not case sensative e.g. 'bc' is fine for 'BC') -i, --income is the gross pay amount (except for commission employees) --advance The amount an employee may have been advanced earlier in the pay period -P, --periods is the number of payperiods in the year (defaults to bi-weekly: 26) --hp Holiday pay rate as a percentage -u, --union Union dues for the pay period -w, --wcb The WCB rate for the employee as a decimal rate e.g. 0.0974 -m, --months is the number of months of the year employee is between 18 and 70 years old.
This is to handle the CPP requirement. Default is 12 (i.e. employee is of age all year) -l, --additional is the amount 'L' of additional tax to be deducted by the employer per TD1 request -y, --yamount as the allowable amount NOT number of deps. Optional Y factor for Ont. and Manitoba. --first First Name. Just to be passed through the script --last Last Name --sin --lcf is the Labour-sponsored funds federal tax credit for the year.Enter the amount deducted or withheld. --lcp is the Labour-sponsored funds provincial tax credit for the year.Enter the amount deducted or withheld. --hd is the annual deduction for living in a prescribed zone from TD1 --rsp Deductions at source for employee contributions to a (RPP), a (RRSP), or a (RCA) --child Annual deductions such as child care expenses and alimony payments --PR If F1 (--child) is implemented after the first payperiod of the year the formula (P × F1) / PR is used
The --PR amount will also work to adjust the K3 amount given in --medical --alimony Alimony or maintenance payments required by a legal document to be deducted at source --medical Other federal tax credits, such as medical expenses and charitable donations --cppytd cpp contributions ytd --eiytd ei contributions ytd --eix ei exempt -C, --commiss commision calculations will be used. Call with a '1' to turn this opt on (e.g. --commiss 1) -G, --grosscom is Gross commission incl. any salary. -I, --icomm equals total remuneration for the year as reported by the employee on Form TD1X --Ac is the number of days since last commission payment --exp total expenses deduction as reported by the employee on Form TD1X
--con Output some print to console
--dict Output a dictionary containing all the vars to console
--csv Output a csv list of vars to console
--dump Dump all vars to console space delimited
--spread Outputs to 'payroll.csv'. Includes labels,totals and will do inserts for new entries.
--ppstart pass-through arg used with --spread
--ppend pass-through arg used with --spread
--rhrs Reg hours and rates. Will calculate 'I' if I==zero
--rrate
--ohrs OT hours and rates. Will calculate 'I' if I==zero
--orate
A brief example:
An employee in AB who's a code 1 from both federal and provincial TD1 forms making 1000 in two weeks (26 pays a year):
cdnpayroll.py -r AB -f 1 -p 1 -i 1000 -P 26
or, with long args:
cdnpayroll.py --resides AB --td1f 1 --td1p 1 --income 1000 --periods 26
You can 'hard-code' some args in quite easily beginning at about line 53 of this script just by typing in some values. So, if you only need to do one province or territory set 'RESIDES' and you'll never have to enter it. Ditto for claim codes, wcb etc. In theory then, you could just call it with the -i argument for income: cndpayroll -i 1543.28
Please bear in mind that this script is intended to be run from either a GUI or another program. Still, ideas for making it a little friendlier from the command line are welcome.
