Commit | Line | Data |
---|---|---|
61cdfff7 FT |
1 | #!/usr/bin/perl -w |
2 | ||
3 | sub gettok { | |
4 | if(/\G\"([^\"]*)\"\s+/gc) { | |
5 | return $1; | |
6 | } elsif(/\G(\S+)\s+/gc) { | |
7 | return $1; | |
8 | } else { | |
9 | return undef; | |
10 | } | |
11 | } | |
12 | ||
13 | while(@ARGV) { | |
14 | if(!open IF, $ARGV[0]) { | |
15 | last; | |
16 | } | |
17 | shift @ARGV; | |
18 | while(<IF>) { | |
19 | if(/^prod\s+/g) { | |
20 | $cp = {}; | |
21 | $id = gettok; | |
22 | $cp->{"s"} = gettok; | |
23 | $cp->{"p"} = gettok; | |
24 | $cp->{"w"} = gettok; | |
25 | $prod{$id} = $cp; | |
26 | } | |
27 | if(/^prt\s+/g) { | |
28 | $id = gettok; | |
29 | $prts{$id} = {"name" => gettok, "items" => {}}; | |
30 | } | |
31 | if(/^item\s+/g) { | |
32 | $prt = gettok; | |
33 | if(!exists $prts{$prt}) { | |
34 | die "invalid participant $prt in item line"; | |
35 | } | |
36 | $a = 1; | |
37 | while($t = gettok) { | |
38 | if($t =~ /^\d+(\.\d+)?$/) { | |
39 | $a = $t; | |
40 | next; | |
41 | } | |
42 | $i = $prts{$prt}->{"items"}; | |
43 | if(exists $i->{$t}) { | |
44 | $i->{$t} += $a; | |
45 | } else { | |
46 | $i->{$t} = $a; | |
47 | } | |
48 | $a = 1; | |
49 | } | |
50 | } | |
51 | if(/^freight\s+(\d+)/) { | |
52 | $fc = $1; | |
53 | } | |
54 | if(/^realprice\s+(\d+)/) { | |
55 | $rp = $1; | |
56 | } | |
57 | } | |
58 | close IF; | |
59 | } | |
60 | ||
61 | $yt = $wt = 0; | |
62 | for $p (sort keys %prts) { | |
63 | $I = $prts{$p}->{"items"}; | |
64 | $sp = $sw = 0; | |
65 | for $i (keys %$I) { | |
66 | $yt += $I->{$i} * $prod{$i}->{"p"}; | |
67 | $wt += $I->{$i} * $prod{$i}->{"w"}; | |
68 | $sp += $I->{$i} * $prod{$i}->{"p"}; | |
69 | $sw += $I->{$i} * $prod{$i}->{"w"}; | |
70 | } | |
71 | $prts{$p}->{"sp"} = $sp; | |
72 | $prts{$p}->{"sw"} = $sw; | |
73 | } | |
74 | $er = (($yt + $fc) / $rp); | |
75 | ||
76 | while($cmd = shift @ARGV) { | |
77 | if($cmd eq "stat") { | |
78 | print "Total: $yt ($rp SEK), $wt g\n"; | |
79 | print "Freight: $fc\n"; | |
80 | print ("Ratio: " . $er . "\n"); | |
81 | } elsif($cmd eq "judgement") { | |
82 | for $prt (keys %prts) { | |
83 | print "$prts{$prt}->{name}:\n"; | |
84 | $sp = $prts{$prt}->{"sp"}; | |
85 | $sw = $prts{$prt}->{"sw"}; | |
86 | printf "\tProducts ¥%i (%i SEK), %i g\n", $sp, ($sp / $er), $sw; | |
87 | $ff = $sw / $wt; | |
88 | $sfc = $fc * $ff; | |
89 | printf "\tFreight ¥%i (%.1f%%, %i SEK)\n", $sfc, (100 * $ff), ($sfc / $er); | |
90 | $st = $sfc + $sp; | |
91 | printf "\tTotal: ¥%i (%i SEK)\n", $st, ($st / $er); | |
92 | } | |
93 | } elsif($cmd eq "rcpt-txt") { | |
94 | $prt = shift @ARGV; | |
95 | $I = $prts{$prt}->{"items"}; | |
96 | for $i (keys %$I) { | |
97 | printf "%.1f %s\t\t%i (%i SEK)\t%i g\n", $I->{$i}, $prod{$i}->{"s"}, $I->{$i} * $prod{$i}->{"p"}, $I->{$i} * $prod{$i}->{"p"} / $er, $I->{$i} * $prod{$i}->{"w"}; | |
98 | } | |
99 | } elsif($cmd eq "rcpt-tex") { | |
100 | print <<EOF | |
101 | \\documentclass[a4paper,11pt]{article} | |
102 | \\usepackage[swedish]{babel} | |
103 | \\usepackage[T1]{fontenc} | |
104 | \\usepackage[utf8x]{inputenc} | |
105 | \\usepackage{longtable} | |
106 | \\title{Kvitto} | |
107 | \\begin{document} | |
108 | \\begin{longtable}{lllllll} | |
109 | Artikel & Antal & \\\'{A}-pris & Pris & Pris (SEK) & Vikt \\\\ | |
110 | \\hline | |
111 | EOF | |
112 | ; | |
113 | $prt = shift @ARGV; | |
114 | $I = $prts{$prt}->{"items"}; | |
115 | $ni = 0; | |
116 | for $i (keys %$I) { | |
117 | printf "%s & ", $prod{$i}->{"s"}; | |
118 | printf "%.1f & ", $I->{$i}; | |
119 | printf "%i & ", $prod{$i}->{"p"}; | |
120 | printf "%i & ", $prod{$i}->{"p"} * $I->{$i}; | |
121 | printf "%.2f & ", $prod{$i}->{"p"} * $I->{$i} / $er; | |
122 | printf "%i & ", $prod{$i}->{"w"} * $I->{$i}; | |
123 | #printf "%.1f %s\t\t%i (%i SEK)\t%i g", $I->{$i}, $prod{$i}->{"s"}, $I->{$i} * $prod{$i}->{"p"}, $I->{$i} * $prod{$i}->{"p"} / $er, $I->{$i} * $prod{$i}->{"w"}; | |
124 | print "\\\\\n"; | |
125 | $ni += $I->{$i}; | |
126 | } | |
127 | print "\\hline\nDelsumma & "; | |
128 | printf "%i & & ", $ni; | |
129 | printf "%i & ", $prts{$prt}->{"sp"}; | |
130 | printf "%.2f & ", $prts{$prt}->{"sp"} / $er; | |
131 | printf "%i & ", $prts{$prt}->{"sw"}; | |
132 | print "\\\\\n"; | |
133 | $ff = $prts{$prt}->{"sw"} / $wt; | |
134 | printf "Frakt & %.1f\\%% & ", 100 * $ff; | |
135 | printf "%i & ", $fc; | |
136 | printf "%i & ", $fc * $ff; | |
137 | printf "%.2f", $fc * $ff / $er; | |
138 | print "\\\\\n"; | |
139 | print "\\hline\nTotalt & & & "; | |
140 | printf "%i & ", $fc * $ff + $prts{$prt}->{"sp"}; | |
141 | printf "\\textbf{%.2f} & ", ($fc * $ff + $prts{$prt}->{"sp"}) / $er; | |
142 | print "\n"; | |
143 | print "\\end{longtable}\n"; | |
144 | print "\n"; | |
145 | print "\\end{document}\n"; | |
146 | } else { | |
147 | print STDERR "usage: ordershare DESCFILE... COMMAND...\n"; | |
148 | print STDERR "\tcommands:\n"; | |
149 | print STDERR "\tstat General statistics\n"; | |
150 | print STDERR "\tjudgement Overview for each participant\n"; | |
151 | print STDERR "\trcpt-txt PARTICIPANT Receipt in text format\n"; | |
152 | print STDERR "\trcpt-tex PARTICIPANT Receipt in LaTeX format\n"; | |
153 | } | |
154 | } |