diff options
Diffstat (limited to 'bin/ne-ifyllning.pl')
-rwxr-xr-x | bin/ne-ifyllning.pl | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/bin/ne-ifyllning.pl b/bin/ne-ifyllning.pl new file mode 100755 index 0000000..27c0459 --- /dev/null +++ b/bin/ne-ifyllning.pl @@ -0,0 +1,116 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use GD::SVG; +use User::pwent; + +my ($full_name) = (User::pwent::getpwnam(getlogin)->gecos)[0] =~ /([^,]*),+$/; + +open FILE, $ARGV[0] or die $!; +my %values; +my ($key, $value); +while (my $line = <FILE>) { + chomp($line); + ($key, $value) = $line =~ /^(.*): *(.*)/g; + $values{$key} = $value; +} +close FILE; + +if ($values{'B9'}-$values{'B14'} ne $values{'B10'}) { + print STDERR "Balanserar icke (B1-B12)!\n"; + exit 1; +} + +if ($values{'R1'}-$values{'R5'} ne $values{'R11'}) { + print STDERR "Balanserar icke! (R1-R11)\n"; + exit 1; +} + +# Bokfört resultat (förs över från B11) +$values{'R12'} = $values{'R11'}; +# Sammanlagt resultat av verksamheten +$values{'R17'} = $values{'R12'}; +# Överskott (+) / Underskott (-) +$values{'R29'} = $values{'R12'}; +# Överskott (+) / Underskott (-), periodiseringsfond +$values{'R33'} = $values{'R29'}; +# Överskott (+) / Underskott (-), expansionsfond +$values{'R35'} = $values{'R33'}; +# Överskott (+) / Underskott (-), före egenavgifter och löneskatt +$values{'R42'} = $values{'R35'}+$values{'R40'}-$values{'R41'}; +# Årets beräknade avdrag för egenavgifter och särskild löneskatt +my $R43_max_deduct = int(($values{'R42'} * 0.075) + 0.5); +if ($R43_max_deduct > 15000) { + $R43_max_deduct = 15000; +} +#my $covid_100k = 100000; +#my $R43 = int(($covid_100k * 0.1021) + (($R42 - $covid_100k) * 0.2897) + 0.5) - $R43_max_deduct; +$values{'R43'} = int(($values{'R42'} * $values{'egenavgifter'}) + 0.5) - $R43_max_deduct; +# Överskott (+) +$values{'R47'} = $values{'R42'}-$values{'R43'}; + +my $ne1 = GD::SVG::Image->new(792, 1122); +my $ne2 = GD::SVG::Image->new(792, 1122); + +my $ne1_white = $ne1->colorAllocate(255,255,255); +my $ne1_black = $ne1->colorAllocate(0,0,0); +my $ne2_white = $ne2->colorAllocate(255,255,255); +my $ne2_black = $ne2->colorAllocate(0,0,0); +my $font = gdLargeFont; + +$ne1->startGroup('ne-1'); +$ne1->rectangle(0,0,792,1122, $ne1_white); + +$ne1->string($font, 420, 152, `date +%Y-%m-%d`, $ne1_black); +$ne1->string($font, 60, 200, $full_name, $ne1_black); +$ne1->string($font, 600, 200, $values{'Personnummer'}, $ne1_black); +$ne1->string($font, 60, 250, $values{'SNI-kategori'}, $ne1_black); +$ne1->string($font, 600, 296, $values{'Personnummer'}, $ne1_black); + +$ne1->string($font, 300, 704, $values{'B9'}, $ne1_black); +$ne1->string($font, 645, 400, $values{'B10'}, $ne1_black); +$ne1->string($font, 645, 641, $values{'B14'}, $ne1_black); + +$ne1->string($font, 300, 785, $values{'R1'}, $ne1_black); +$ne1->string($font, 300, 945, $values{'R5'}, $ne1_black); +$ne1->string($font, 645, 898, $values{'R11'}, $ne1_black); + +# Uppdragstagare har biträtt vid upprättandet +$ne1->string(gdGiantFont, 583, 980, 'x', $ne1_black); + +$ne1->endGroup; + +my $ne2_left_col = 320; +my $ne2_right_col = 675; +# my $ne2_line_height = 35.78; # Lines differ in height... + +$ne2->startGroup('ne-2'); +$ne2->rectangle(0, 0, 792, 1122, $ne2_white); + +$ne2->string($font, 600, 50, $values{'Personnummer'}, $ne2_black); + +$ne2->string($font, $ne2_left_col, 112, $values{'R12'}, $ne2_black); +$ne2->string($font, $ne2_left_col, 271, $values{'R17'}, $ne2_black); +$ne2->string($font, $ne2_right_col, 206, $values{'R33'}, $ne2_black); +$ne2->string($font, $ne2_right_col, 271, $values{'R35'}, $ne2_black); +$ne2->string($font, $ne2_right_col, 451, $values{'R40'}, $ne2_black); +$ne2->string($font, $ne2_right_col, 485, $values{'R41'}, $ne2_black); +$ne2->string($font, $ne2_right_col, 519, $values{'R42'}, $ne2_black); +$ne2->string($font, $ne2_right_col, 553, $values{'R43'}, $ne2_black); +$ne2->string($font, $ne2_right_col, 703, $values{'R47'}, $ne2_black); +$ne2->string($font, $ne2_left_col, 735, $values{'R29'}, $ne2_black); + +$ne2->endGroup; + +open(SVGFILE, ">ne1-overlay.svg"); +print SVGFILE $ne1->svg; +open(SVGFILE, ">ne2-overlay.svg"); +print SVGFILE $ne2->svg; + +open(FILE, '>', $ARGV[0]."-out"); + for (keys %values ) { + print FILE $_.": ".$values{$_}."\n"; + } +close FILE; |