summaryrefslogtreecommitdiff
path: root/bin/ne-ifyllning.pl
blob: 27c0459a1bb9bf840d122a5ac7b85ecfcd3f1fcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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;