| 1 | #!/usr/local/bin/perl | ||
| 2 | use warnings; | ||
| 3 | use strict; | ||
| 4 | |||
| 5 | # PODNAME: loon.pl | ||
| 6 | # ABSTRACT: A salary cost calculator | ||
| 7 | |||
| 8 | use Data::Dumper; | ||
| 9 | use DateTime; | ||
| 10 | use Finance::Tax::Aruba::Income; | ||
| 11 | use Getopt::Long; | ||
| 12 | use Pod::Usage; | ||
| 13 | use Text::Table; | ||
| 14 | |||
| 15 | my %opts = ( | ||
| 16 | months => 12, | ||
| 17 | help => 0, | ||
| 18 | cur => 'awg', | ||
| 19 | yearly => 0, | ||
| 20 | ); | ||
| 21 | |||
| 22 | { | ||
| 23 | local $SIG{__WARN__}; | ||
| 24 | my $ok = eval { | ||
| 25 | GetOptions(\%opts, qw( | ||
| 26 | help | ||
| 27 | cur=s | ||
| 28 | months=i | ||
| 29 | rate=f | ||
| 30 | from | ||
| 31 | year=i | ||
| 32 | yearly | ||
| 33 | ), | ||
| 34 | 'as-np', | ||
| 35 | 'no-pension', | ||
| 36 | 'premiums-employer', | ||
| 37 | 'pension-employee=f', | ||
| 38 | 'pension-employer=f', | ||
| 39 | 'tax-free=f', | ||
| 40 | 'bonus=f', | ||
| 41 | 'fringe=f', | ||
| 42 | ); | ||
| 43 | }; | ||
| 44 | if (!$ok) { | ||
| 45 | die($@); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | pod2usage(0) if ($opts{help}); | ||
| 50 | pod2usage(1) if !$ARGV[0]; | ||
| 51 | |||
| 52 | $opts{cur} = lc($opts{cur}); | ||
| 53 | |||
| 54 | sub to_awg { | ||
| 55 | my $cur = shift; | ||
| 56 | return $cur if $opts{cur} eq 'awg'; | ||
| 57 | |||
| 58 | $opts{rate} ||= 1.79 if $opts{cur} eq 'usd'; | ||
| 59 | $opts{rate} ||= 2; | ||
| 60 | |||
| 61 | return $cur * $opts{rate} if $opts{from}; | ||
| 62 | return $cur; | ||
| 63 | } | ||
| 64 | |||
| 65 | sub to_cur { | ||
| 66 | my $cur = shift; | ||
| 67 | return $cur if $opts{cur} eq 'awg'; | ||
| 68 | return $cur / $opts{rate}; | ||
| 69 | } | ||
| 70 | |||
| 71 | my $maandloon = to_awg($ARGV[0]); | ||
| 72 | my $months = $opts{months}; | ||
| 73 | |||
| 74 | $opts{'tax-free'} = ($opts{'tax-free'} // 0) * $months; | ||
| 75 | $opts{'fringe'} //= 0; | ||
| 76 | |||
| 77 | if ($opts{yearly}) { | ||
| 78 | $maandloon = $maandloon / $months; | ||
| 79 | } | ||
| 80 | |||
| 81 | $opts{year} //= DateTime->now->year; | ||
| 82 | |||
| 83 | my $calc = Finance::Tax::Aruba::Income->tax_year( | ||
| 84 | $opts{year}, | ||
| 85 | income => $maandloon, | ||
| 86 | months => $opts{months}, | ||
| 87 | |||
| 88 | exists $opts{'as-np'} ? ( as_np => 1) : ( | ||
| 89 | exists $opts{'pension-employee'} ? | ||
| 90 | ( | ||
| 91 | pension_employee_perc => $opts{'pension-employee'}, | ||
| 92 | ) : (), | ||
| 93 | exists $opts{'pension-employer'} ? | ||
| 94 | ( | ||
| 95 | pension_employer_perc => $opts{'pension-employer'}, | ||
| 96 | ) : (), | ||
| 97 | exists $opts{'fringe'} | ||
| 98 | ? (fringe => $opts{'fringe'}) | ||
| 99 | : (), | ||
| 100 | exists $opts{'no-pension'} ? (no_pension => 1) : (), | ||
| 101 | exists $opts{'premiums-employer'} ? (premiums_employer => 1) : (), | ||
| 102 | exists $opts{'bonus'} | ||
| 103 | ? (bonus => $opts{'bonus'}) | ||
| 104 | : (), | ||
| 105 | exists $opts{'tax-free'} | ||
| 106 | ? (tax_free => $opts{'tax-free'}) | ||
| 107 | : (), | ||
| 108 | ), | ||
| 109 | |||
| 110 | |||
| 111 | |||
| 112 | ); | ||
| 113 | |||
| 114 | sub _p { | ||
| 115 | my $val = shift; | ||
| 116 | my $decimal = shift // 2; | ||
| 117 | return sprintf("%.${decimal}f", $val); | ||
| 118 | } | ||
| 119 | |||
| 120 | my @header = qw(what awg/y awg/m); | ||
| 121 | |||
| 122 | if ($opts{cur} ne 'awg') { | ||
| 123 | push(@header, 'conv', "$opts{cur}/y", "$opts{cur}/m"); | ||
| 124 | } | ||
| 125 | |||
| 126 | my @order = qw( | ||
| 127 | - | ||
| 128 | income | ||
| 129 | fringe | ||
| 130 | bonus | ||
| 131 | bruto | ||
| 132 | - | ||
| 133 | werving | ||
| 134 | pensioen_employee | ||
| 135 | jaarloon | ||
| 136 | - | ||
| 137 | azv | ||
| 138 | aov | ||
| 139 | - | ||
| 140 | zuiver | ||
| 141 | tabelinkomen | ||
| 142 | taxed | ||
| 143 | rate | ||
| 144 | fixed_tax | ||
| 145 | var_tax | ||
| 146 | total_tax | ||
| 147 | reparatietoeslag | ||
| 148 | - | ||
| 149 | free | ||
| 150 | netto | ||
| 151 | tax_free | ||
| 152 | wage | ||
| 153 | - | ||
| 154 | azv_employer | ||
| 155 | aov_employer | ||
| 156 | pensioen_employer | ||
| 157 | - | ||
| 158 | cost_employer | ||
| 159 | total_cost_employer | ||
| 160 | - | ||
| 161 | azv_total | ||
| 162 | aov_total | ||
| 163 | total_tax | ||
| 164 | gov_costs | ||
| 165 | - | ||
| 166 | pensioen | ||
| 167 | social_costs | ||
| 168 | ); | ||
| 169 | |||
| 170 | my $jaarloon_bruto = $calc->yearly_income_gross; | ||
| 171 | my $jaarloon = $calc->yearly_income; | ||
| 172 | |||
| 173 | my $pensioen = $calc->pension_total; | ||
| 174 | my $tax_free = $calc->taxfree_amount; | ||
| 175 | |||
| 176 | my %year = ( | ||
| 177 | income => $calc->income, | ||
| 178 | bruto => $calc->yearly_income_gross, | ||
| 179 | jaarloon => $calc->yearly_income, | ||
| 180 | netto => $calc->tax_free_wage, | ||
| 181 | werving => $calc->wervingskosten, | ||
| 182 | azv => $calc->azv_employee, | ||
| 183 | aov => $calc->aov_employee, | ||
| 184 | zuiver => $calc->zuiver_jaarloon, | ||
| 185 | tabelinkomen => $calc->taxable_wage, | ||
| 186 | taxed => $calc->taxable_amount, | ||
| 187 | fixed_tax => $calc->tax_fixed, | ||
| 188 | var_tax => $calc->tax_variable, | ||
| 189 | total_tax => $calc->income_tax, | ||
| 190 | reparatietoeslag => $calc->reparatietoeslag, | ||
| 191 | rate => $calc->tax_rate, | ||
| 192 | azv_employer => $calc->azv_employer, | ||
| 193 | aov_employer => $calc->aov_employer, | ||
| 194 | conv_rate => $opts{rate}, | ||
| 195 | free => $calc->taxfree_amount, | ||
| 196 | wage => $calc->net_income, | ||
| 197 | pensioen_employee => $calc->pension_employee, | ||
| 198 | pensioen_employer => $calc->pension_employer, | ||
| 199 | pensioen => $calc->pension_total, | ||
| 200 | total_cost_employer => $calc->company_costs, | ||
| 201 | gov_costs => $calc->government_costs, | ||
| 202 | social_costs => $calc->social_costs, | ||
| 203 | azv_total => $calc->azv_premium, | ||
| 204 | aov_total => $calc->aov_premium, | ||
| 205 | tax_free => $calc->tax_free, | ||
| 206 | bonus => $calc->bonus, | ||
| 207 | fringe => $calc->fringe, | ||
| 208 | cost_employer => $calc->pension_employer + $calc->azv_employer + $calc->aov_employer, | ||
| 209 | ); | ||
| 210 | |||
| 211 | my %mapping = ( | ||
| 212 | income => 'Inkomen', | ||
| 213 | bruto => 'Bruto', | ||
| 214 | jaarloon => 'Jaarloon', | ||
| 215 | netto => 'Netto', | ||
| 216 | werving => 'Wervingskosten', | ||
| 217 | azv => sprintf('AZV (%s%%)', $calc->azv_percentage_employee), | ||
| 218 | azv_employer => sprintf('AZV (%s%%)', $calc->azv_percentage_employer), | ||
| 219 | aov => sprintf('AOV/AWW (%s%%)', $calc->aov_percentage_employee), | ||
| 220 | aov_employer => sprintf('AOV/AWW (%s%%)', $calc->aov_percentage_employer), | ||
| 221 | zuiver => 'Zuiver jaarloon', | ||
| 222 | tabelinkomen => 'Tabelinkomen', | ||
| 223 | taxed => 'Belastbaar inkomen', | ||
| 224 | fixed_tax => 'Vaste belasting', | ||
| 225 | var_tax => 'Variable belasting', | ||
| 226 | total_tax => 'Totale belastingen', | ||
| 227 | reparatietoeslag => 'Reparatietoeslag', | ||
| 228 | rate => 'Belastingtarief', | ||
| 229 | effective_rate => 'Effectief belastingtarief', | ||
| 230 | $opts{rate} ? (conv_rate => "$opts{rate}awg/1eur") : (), | ||
| 231 | free => "Belastingvrije voet", | ||
| 232 | tax_free => "Onbelastbaar inkomen", | ||
| 233 | wage => "Uit te betalen loon", | ||
| 234 | pensioen_employee => sprintf('Pension (%s%%)', $calc->pension_employee_perc), | ||
| 235 | pensioen_employer => sprintf('Pension (%s%%)', $calc->pension_employer_perc), | ||
| 236 | pensioen => sprintf('Pension Totaal (%s%%)', | ||
| 237 | $calc->pension_employee_perc + $calc->pension_employer_perc), | ||
| 238 | total_cost_employer => "Totale loonkosten bedrijf", | ||
| 239 | cost_employer => "Additionele loonkosten", | ||
| 240 | |||
| 241 | azv_total => sprintf('AZV Totaal (%s%%)', | ||
| 242 | $calc->azv_percentage_employee + $calc->azv_percentage_employer), | ||
| 243 | |||
| 244 | aov_total => sprintf('OAV/AWW Totaal (%s%%)', | ||
| 245 | $calc->aov_percentage_employee + $calc->aov_percentage_employer), | ||
| 246 | |||
| 247 | gov_costs => "Government costs", | ||
| 248 | social_costs => "Social costs", | ||
| 249 | |||
| 250 | bonus => "Bonus", | ||
| 251 | fringe => "Fringe benefits" | ||
| 252 | ); | ||
| 253 | |||
| 254 | my ($longest) = sort { length($b) <=> length($a) } values %mapping; | ||
| 255 | my $l = length($longest); | ||
| 256 | $mapping{'-'} = '-' x $l; | ||
| 257 | |||
| 258 | my @rows; | ||
| 259 | |||
| 260 | foreach (@order) { | ||
| 261 | if ($_ eq '-') { | ||
| 262 | push(@rows, [$mapping{$_}, map { '---------' } (0 .. 4)]); | ||
| 263 | } | ||
| 264 | elsif ($_ eq 'rate' || $_ eq 'effective_rate') { | ||
| 265 | push( | ||
| 266 | @rows, | ||
| 267 | [ | ||
| 268 | $mapping{$_}, _p($year{$_}), _p($year{$_}), | ||
| 269 | $opts{cur} ne 'awg' ? ('', _p($year{$_}), _p($year{$_})) : (), | ||
| 270 | ] | ||
| 271 | ); | ||
| 272 | } | ||
| 273 | else { | ||
| 274 | die "$_ is missing\n" if !defined $year{$_}; | ||
| 275 | push( | ||
| 276 | @rows, | ||
| 277 | [ | ||
| 278 | $mapping{$_}, | ||
| 279 | _p($year{$_}), | ||
| 280 | _p($year{$_} / $months), | ||
| 281 | $opts{cur} ne 'awg' | ||
| 282 | ? ( | ||
| 283 | _p($opts{rate}, 4), _p(to_cur($year{$_})), | ||
| 284 | _p(to_cur($year{$_} / $months)) | ||
| 285 | ) | ||
| 286 | : (), | ||
| 287 | ] | ||
| 288 | ); | ||
| 289 | } | ||
| 290 | } | ||
| 291 | |||
| 292 | my $tb = Text::Table->new(@header); | ||
| 293 | |||
| 294 | print $tb->load(@rows); | ||
| 295 | |||
| 296 | __END__ |