| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #! perl | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # Reporter.pm -- | 
| 4 |  |  |  |  |  |  | # Author          : Johan Vromans | 
| 5 |  |  |  |  |  |  | # Created On      : Wed Dec 28 13:18:40 2005 | 
| 6 |  |  |  |  |  |  | # Last Modified By: Johan Vromans | 
| 7 |  |  |  |  |  |  | # Last Modified On: Sat Jun 19 00:40:09 2010 | 
| 8 |  |  |  |  |  |  | # Update Count    : 152 | 
| 9 |  |  |  |  |  |  | # Status          : Unknown, Use with caution! | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | package main; | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | our $cfg; | 
| 14 |  |  |  |  |  |  | our $dbh; | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | package EB::Report::Reporter; | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 1 |  |  | 1 |  | 7 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 23 |  | 
| 19 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 19 |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 1 |  |  | 1 |  | 4 | use EB; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 151 |  | 
| 22 | 1 |  |  | 1 |  | 6 | use EB::Format; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 1019 |  | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | sub new { | 
| 25 | 0 |  |  | 0 | 0 |  | my ($class, $style, $config) = @_; | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 0 | 0 |  |  |  |  | if ( @_ == 2 ) { | 
| 28 | 0 |  |  |  |  |  | $config = $style->{LAYOUT}; | 
| 29 | 0 |  |  |  |  |  | $style  = $style->{STYLE}; | 
| 30 |  |  |  |  |  |  | } | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 0 |  | 0 |  |  |  | $class = ref($class) || $class; | 
| 33 | 0 |  |  |  |  |  | my $self = bless { _fields => [], | 
| 34 |  |  |  |  |  |  | _fdata  => {}, | 
| 35 |  |  |  |  |  |  | _style  => $style, | 
| 36 |  |  |  |  |  |  | }, $class; | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 0 |  |  |  |  |  | foreach my $col ( @$config ) { | 
| 39 | 0 | 0 |  |  |  |  | if ( $col->{name} ) { | 
| 40 | 0 | 0 |  |  |  |  | if ( $col->{name} eq "_colsep" ) { | 
| 41 | 0 |  | 0 |  |  |  | $self->{_colsep} = $col->{sep} || (" " x $col->{width}); | 
| 42 | 0 |  |  |  |  |  | next; | 
| 43 |  |  |  |  |  |  | } | 
| 44 | 0 |  |  |  |  |  | my $a = { name  => $col->{name} }; | 
| 45 | 0 |  | 0 |  |  |  | $a->{title} = $col->{title} || ""; | 
| 46 | 0 |  | 0 |  |  |  | $a->{width} = $col->{width} || length($a->{title}); | 
| 47 | 0 |  | 0 |  |  |  | $a->{align} = $col->{align} || "<"; | 
| 48 | 0 |  | 0 |  |  |  | $a->{style} = $col->{style} || $col->{name}; | 
| 49 | 0 |  |  |  |  |  | $self->{_fdata}->{$a->{name}} = $a; | 
| 50 | 0 |  |  |  |  |  | push(@{$self->{_fields}}, $a); | 
|  | 0 |  |  |  |  |  |  | 
| 51 | 0 | 0 |  |  |  |  | if ( my $t = $cfg->val("layout $style", $col->{name}."_width", undef) ) { | 
| 52 | 0 |  |  |  |  |  | $self->widths({$col->{name} => $t}); | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  | else { | 
| 56 | 0 |  |  |  |  |  | die("?"._T("Ontbrekend \"name\" of \"style\"")); | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  |  | 
| 60 | 0 | 0 |  |  |  |  | if ( my $t = $cfg->val("layout $style", "fields", undef) ) { | 
| 61 | 0 |  |  |  |  |  | $self->fields(split(' ', $t)); | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | # Return object. | 
| 65 | 0 |  |  |  |  |  | $self; | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | sub fields { | 
| 69 | 0 |  |  | 0 | 0 |  | my ($self, @f) = @_; | 
| 70 |  |  |  |  |  |  |  | 
| 71 | 0 |  |  |  |  |  | my @nf;			# new order of fields | 
| 72 |  |  |  |  |  |  |  | 
| 73 | 0 |  |  |  |  |  | foreach my $fld ( @f ) { | 
| 74 | 0 |  |  |  |  |  | my $a = $self->{_fdata}->{$fld}; | 
| 75 | 0 | 0 |  |  |  |  | die("?".__x("Onbekend veld: {fld}", fld => $fld)."\n") | 
| 76 |  |  |  |  |  |  | unless defined($a); | 
| 77 | 0 |  |  |  |  |  | push(@nf, $a); | 
| 78 |  |  |  |  |  |  | } | 
| 79 | 0 |  |  |  |  |  | $self->{_fields} = \@nf; | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | # PBP: Return nothing sensible. | 
| 82 | 0 |  |  |  |  |  | return; | 
| 83 |  |  |  |  |  |  | } | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | sub widths { | 
| 86 | 0 |  |  | 0 | 0 |  | my ($self, $w) = @_; | 
| 87 |  |  |  |  |  |  |  | 
| 88 | 0 |  |  |  |  |  | while ( my($fld,$width) = each(%$w) ) { | 
| 89 |  |  |  |  |  |  | die("?".__x("Onbekend veld: {fld}", fld => $fld)."\n") | 
| 90 | 0 | 0 |  |  |  |  | unless defined($self->{_fdata}->{$fld}); | 
| 91 | 0 |  |  |  |  |  | my $ow = $self->{_fdata}->{$fld}->{width}; | 
| 92 | 0 | 0 |  |  |  |  | if ( $width =~ /^\+(\d+)$/ ) { | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
|  |  | 0 |  |  |  |  |  | 
| 93 | 0 |  |  |  |  |  | $ow += $1; | 
| 94 |  |  |  |  |  |  | } | 
| 95 |  |  |  |  |  |  | elsif ( $width =~ /^-(\d+)$/ ) { | 
| 96 | 0 |  |  |  |  |  | $ow -= $1; | 
| 97 |  |  |  |  |  |  | } | 
| 98 |  |  |  |  |  |  | elsif ( $width =~ /^(\d+)\%$/ ) { | 
| 99 | 0 |  |  |  |  |  | $ow *= $1; | 
| 100 | 0 |  |  |  |  |  | $ow = int($ow/100); | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  | elsif ( $width =~ /^\d+$/ ) { | 
| 103 | 0 |  |  |  |  |  | $ow = $width; | 
| 104 |  |  |  |  |  |  | } | 
| 105 |  |  |  |  |  |  | else { | 
| 106 | 0 |  |  |  |  |  | die("?".__x("Ongeldige breedte {w} voor veld {fld}", | 
| 107 |  |  |  |  |  |  | fld => $fld, w => $width)."\n"); | 
| 108 |  |  |  |  |  |  | } | 
| 109 | 0 |  |  |  |  |  | $self->{_fdata}->{$fld}->{width} = $ow; | 
| 110 |  |  |  |  |  |  | } | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | # PBP: Return nothing sensible. | 
| 113 | 0 |  |  |  |  |  | return; | 
| 114 |  |  |  |  |  |  | } | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | sub start { | 
| 117 | 0 |  |  | 0 | 0 |  | my $self = shift; | 
| 118 | 0 |  |  |  |  |  | my ($t1, $t2, $t3l, $t3r) = @_; | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | # Top title. | 
| 121 | 0 | 0 |  |  |  |  | if ( !$t1 ) { | 
| 122 |  |  |  |  |  |  | # This one really should be filled in with something distinguishing. | 
| 123 | 0 |  |  |  |  |  | $t1 = _T("Rapportage"); | 
| 124 |  |  |  |  |  |  | } | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | # Report date / period. | 
| 127 | 0 | 0 |  |  |  |  | if ( !$t2 ) { | 
| 128 | 0 |  |  |  |  |  | $t2 = "Periode: ****"; | 
| 129 | 0 | 0 |  |  |  |  | if ( exists($self->{periodex}) ) { | 
| 130 | 0 | 0 |  |  |  |  | if ( $self->{periodex} == 1 ) { | 
| 131 |  |  |  |  |  |  | $t2 = __x("Periode: t/m {to}", | 
| 132 | 0 |  |  |  |  |  | to   => datefmt_full($self->{periode}->[1])); | 
| 133 |  |  |  |  |  |  | } | 
| 134 |  |  |  |  |  |  | else { | 
| 135 |  |  |  |  |  |  | $t2 = __x("Periode: {from} t/m {to}", | 
| 136 |  |  |  |  |  |  | from => datefmt_full($self->{periode}->[0]), | 
| 137 | 0 |  |  |  |  |  | to   => datefmt_full($self->{periode}->[1])); | 
| 138 |  |  |  |  |  |  | } | 
| 139 |  |  |  |  |  |  | } | 
| 140 |  |  |  |  |  |  | } | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | # Administration name. | 
| 143 | 0 | 0 |  |  |  |  | if ( !$t3l ) { | 
| 144 | 0 |  |  |  |  |  | $t3l = $::dbh->adm("name"); | 
| 145 |  |  |  |  |  |  | } | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | # Creation date + program version | 
| 148 | 0 | 0 |  |  |  |  | if ( !$t3r ) { | 
| 149 | 0 | 0 |  |  |  |  | if ( my $t = $cfg->val(qw(internal now), 0) ) { | 
| 150 |  |  |  |  |  |  | # Fixed date. Strip program version. Makes it easier to compare reports. | 
| 151 | 0 |  |  |  |  |  | $t3r = (split(' ', $EB::ident))[0] . ", " . $t; | 
| 152 |  |  |  |  |  |  | } | 
| 153 |  |  |  |  |  |  | else { | 
| 154 |  |  |  |  |  |  | # Use current date. | 
| 155 | 0 |  |  |  |  |  | $t3r = $EB::ident . ", " . datefmt_full(iso8601date()); | 
| 156 |  |  |  |  |  |  | } | 
| 157 |  |  |  |  |  |  | } | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | # Move to self. | 
| 160 | 0 |  |  |  |  |  | $self->{_title1}  = $t1; | 
| 161 | 0 |  |  |  |  |  | $self->{_title2}  = $t2; | 
| 162 | 0 |  |  |  |  |  | $self->{_title3l} = $t3l; | 
| 163 | 0 |  |  |  |  |  | $self->{_title3r} = $t3r; | 
| 164 |  |  |  |  |  |  |  | 
| 165 | 0 |  |  |  |  |  | $self->{_needhdr} = 1; | 
| 166 | 0 |  |  |  |  |  | $self->{_needskip} = 0; | 
| 167 | 0 |  | 0 |  |  |  | $self->{fh} ||= *STDOUT; | 
| 168 |  |  |  |  |  |  | } | 
| 169 |  |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  | sub finish { | 
| 171 | 0 |  |  | 0 | 0 |  | my ($self) = @_; | 
| 172 |  |  |  |  |  |  | } | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | sub add { | 
| 175 | 0 |  |  | 0 | 0 |  | my ($self, $data) = @_; | 
| 176 |  |  |  |  |  |  |  | 
| 177 | 0 |  |  |  |  |  | while ( my($k,$v) = each(%$data) ) { | 
| 178 |  |  |  |  |  |  | die("?",__x("Ongeldig veld: {fld}", fld => $k)) | 
| 179 | 0 | 0 |  |  |  |  | unless defined $self->{_fdata}->{$k}; | 
| 180 |  |  |  |  |  |  | } | 
| 181 |  |  |  |  |  |  |  | 
| 182 |  |  |  |  |  |  | } | 
| 183 |  |  |  |  |  |  |  | 
| 184 | 0 |  |  | 0 | 0 |  | sub style { return } | 
| 185 |  |  |  |  |  |  |  | 
| 186 |  |  |  |  |  |  | sub _getstyle { | 
| 187 | 0 |  |  | 0 |  |  | my ($self, $row, $cell) = @_; | 
| 188 | 0 | 0 |  |  |  |  | return $self->style($row) unless $cell; | 
| 189 |  |  |  |  |  |  |  | 
| 190 | 0 |  | 0 |  |  |  | my $a = $self->style("_any", $cell) || {}; | 
| 191 | 0 |  | 0 |  |  |  | my $b = $self->style($row, $cell) || {}; | 
| 192 | 0 |  |  |  |  |  | return { %$a, %$b }; | 
| 193 |  |  |  |  |  |  | } | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | sub _checkhdr { | 
| 196 | 0 |  |  | 0 |  |  | my ($self) = @_; | 
| 197 | 0 | 0 |  |  |  |  | return unless $self->{_needhdr}; | 
| 198 | 0 |  |  |  |  |  | $self->{_needhdr} = 0; | 
| 199 | 0 |  |  |  |  |  | $self->header; | 
| 200 |  |  |  |  |  |  | } | 
| 201 |  |  |  |  |  |  |  | 
| 202 |  |  |  |  |  |  | 1; |