| 1 | # Payroll::AU::PAYG. | ||
| 2 | # | ||
| 3 | # Paul Fenwick <pjf@cpan.org>, August 2003. | ||
| 4 | # | ||
| 5 | # This module computes PAYG withholding for Australian workers. | ||
| 6 | # | ||
| 7 | # This is a cheat, it simply queries the ATO's on-line calcuator. | ||
| 8 | # | ||
| 9 | # The interface should be fleshed out and properly defined. | ||
| 10 | # | ||
| 11 | # Anyone who wants to become the maintainer of this module and raise | ||
| 12 | # to fame and fortune should get in contact with me directly at | ||
| 13 | # pjf@cpan.org | ||
| 14 | |||
| 15 | package Payroll::AU::PAYG; | ||
| 16 | use strict; | ||
| 17 | use warnings; | ||
| 18 | |||
| 19 | use LWP::UserAgent; | ||
| 20 | |||
| 21 | our $VERSION = 0.01; | ||
| 22 | |||
| 23 | my %defaults = ( | ||
| 24 | CalculatorType => 1, | ||
| 25 | PayeeName => "Employee", | ||
| 26 | TFNABNProvided => "Y", | ||
| 27 | TFNABNExempt => "N", | ||
| 28 | AustralianResident => "Y", | ||
| 29 | TaxFreeThresholdClaimed => "Y", | ||
| 30 | RebateAndFTAAmountClaimed => 0, | ||
| 31 | MedicareVariation => 0, | ||
| 32 | MedicareReducedRate => "N", | ||
| 33 | HasSpouse => "N", | ||
| 34 | CombinedIncLessAmtRR => "N", | ||
| 35 | DependentChildrenClaimed => 0, | ||
| 36 | CalculationPeriod => 1, | ||
| 37 | GrossEarnings => 0, | ||
| 38 | HECSDebt => "N", | ||
| 39 | SFSSDebt => "N", | ||
| 40 | EntitledAnnualLeaveLoading => "N", | ||
| 41 | ); | ||
| 42 | |||
| 43 | my %mappings = ( | ||
| 44 | CalculatorType => { | ||
| 45 | individual => 0, | ||
| 46 | labour => 1, | ||
| 47 | voluntary => 2, | ||
| 48 | }, | ||
| 49 | CalculationPeriod => { | ||
| 50 | weekly => 0, | ||
| 51 | fortnightly => 1, | ||
| 52 | monthly => 2, | ||
| 53 | quarterly => 3 | ||
| 54 | }, | ||
| 55 | ); | ||
| 56 | |||
| 57 | my %fields = ( | ||
| 58 | gross => qr/Gross \w+ Earnings/, | ||
| 59 | tax => qr/Tax Applicable/, | ||
| 60 | rebates => qr/Less Rebates and Family Tax Benefit/, | ||
| 61 | medicare => qr/Less Medicare Levy Adjustment/, | ||
| 62 | withheld => qr/Tax Withheld Amounts/, | ||
| 63 | net => qr/Net Pay/, | ||
| 64 | ); | ||
| 65 | |||
| 66 | our $ONLINE_CALC = "http://www.ato.gov.au/scripts/taxcalc/calculate_tax.asp"; | ||
| 67 | |||
| 68 | # Really just a stub right now. | ||
| 69 | sub new { | ||
| 70 | my $class = shift; | ||
| 71 | return bless({},$class); | ||
| 72 | } | ||
| 73 | |||
| 74 | # Actually figure out the amounts and return them. | ||
| 75 | sub calculate { | ||
| 76 | my ($this, %args) = @_; | ||
| 77 | %args = (%defaults, %args); | ||
| 78 | |||
| 79 | # Set the UserAgent if we don't already have one. | ||
| 80 | my $ua = $this->{UserAgent} ||= LWP::UserAgent->new; | ||
| 81 | |||
| 82 | # For some reason we need to pretend to be Mozilla, not | ||
| 83 | # LWP. The ATO doesn't like agents it hasn't heard of. | ||
| 84 | my $response = $ua->post($ONLINE_CALC,\%args, | ||
| 85 | "User-Agent" => "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020606", | ||
| 86 | ); | ||
| 87 | |||
| 88 | unless ($response->is_success) { | ||
| 89 | die "Failed ".__PACKAGE__." calculate -- ".$response->error_as_HTML; | ||
| 90 | } | ||
| 91 | |||
| 92 | my $content = $response->content; | ||
| 93 | |||
| 94 | my %return = (); | ||
| 95 | |||
| 96 | foreach my $heading (keys %fields) { | ||
| 97 | ($return{$heading}) = $content =~ | ||
| 98 | m! | ||
| 99 | $fields{$heading} # Our heading | ||
| 100 | [^\$]+? # Non-dollars | ||
| 101 | \$([\d,]+\.\d\d) # The amount. | ||
| 102 | </(?i:td)> # Close tag. | ||
| 103 | !sx; | ||
| 104 | $return{$heading} =~ tr/,//d; | ||
| 105 | } | ||
| 106 | |||
| 107 | return \%return; | ||
| 108 | } | ||
| 109 | |||
| 110 | 1; |