Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 824edcc4

Von Steven Schubiger vor mehr als 2 Jahren hinzugefügt

  • ID 824edcc40cb27a8f00265999abb2a2ce065dfbb2
  • Vorgänger 16485ecf
  • Nachfolger 2fd4736b

Swiss QR-Bill: QrBill.pm: Überarbeite _init_check()

sodass Logik und Daten besser getrennt sind.

Unterschiede anzeigen:

SL/Helper/QrBill.pm
86 86
    die "field '$elem' in group '$group' $error", "\n" if defined $error;
87 87
  };
88 88

  
89
  my %regexes = (
90
    'biller information' => [
91
      [ 'iban', qr{^(?:CH|LI)[0-9a-zA-Z]{19}$} ],
92
    ],
93
    'biller data' => [
94
      [ 'address_type', qr{^[KS]$}     ],
95
      [ 'company',      qr{^.{1,70}$}  ],
96
      [ 'address_row1', qr{^.{0,70}$}  ],
97
      [ 'address_row2', qr{^.{0,70}$}  ],
98
      [ 'street',       qr{^.{0,70}$}  ],
99
      [ 'street_no',    qr{^.{0,16}$}  ],
100
      [ 'postalcode',   qr{^.{0,16}$}  ],
101
      [ 'city',         qr{^.{0,35}$}  ],
102
      [ 'countrycode',  qr{^[A-Z]{2}$} ],
103
    ],
104
    'payment information' => [
105
      [ 'amount',   qr{^(?:(?:0|[1-9][0-9]{0,8})\.[0-9]{2})?$} ],
106
      [ 'currency', qr{^(?:CHF|EUR)$}                          ],
107
    ],
108
    'invoice recipient data' => [
109
      [ 'address_type', qr{^[KS]$}     ],
110
      [ 'name',         qr{^.{1,70}$}  ],
111
      [ 'address_row1', qr{^.{0,70}$}  ],
112
      [ 'address_row2', qr{^.{0,70}$}  ],
113
      [ 'street',       qr{^.{0,70}$}  ],
114
      [ 'street_no',    qr{^.{0,16}$}  ],
115
      [ 'postalcode',   qr{^.{0,16}$}  ],
116
      [ 'city',         qr{^.{0,35}$}  ],
117
      [ 'countrycode',  qr{^[A-Z]{2}$} ],
118
    ],
119
    'reference number data' => [
120
      [ 'type', qr{^(?:QRR|SCOR|NON)$} ],
121
    ],
122
  );
123

  
89 124
  my $group = 'biller information';
90
  $check_re->($group, $biller_information, 'iban', qr{^(?:CH|LI)[0-9a-zA-Z]{19}$});
125
  foreach my $re (@{$regexes{$group}}) {
126
    $check_re->($group, $biller_information, @$re);
127
  }
91 128

  
92 129
  $group = 'biller data';
93
  $check_re->($group, $biller_data, 'address_type', qr{^[KS]$});
94
  $check_re->($group, $biller_data, 'company', qr{^.{1,70}$});
130
  foreach my $re (grep $_->[0] =~ /^(?:address_type|company)$/, @{$regexes{$group}}) {
131
    $check_re->($group, $biller_data, @$re);
132
  }
95 133
  if ($biller_data->{address_type} eq 'K') {
96
    $check_re->($group, $biller_data, 'address_row1', qr{^.{0,70}$});
97
    $check_re->($group, $biller_data, 'address_row2', qr{^.{0,70}$});
134
    foreach my $re (grep $_->[0] =~ /^address_row[12]$/, @{$regexes{$group}}) {
135
      $check_re->($group, $biller_data, @$re);
136
    }
98 137
  } elsif ($biller_data->{address_type} eq 'S') {
99
    $check_re->($group, $biller_data, 'street', qr{^.{0,70}$});
100
    $check_re->($group, $biller_data, 'street_no', qr{^.{0,16}$});
101
    $check_re->($group, $biller_data, 'postalcode', qr{^.{0,16}$});
102
    $check_re->($group, $biller_data, 'city', qr{^.{0,35}$});
138
    foreach my $re (grep $_->[0] =~ /^(?:street(?:_no)?|postalcode|city)$/, @{$regexes{$group}}) {
139
      $check_re->($group, $biller_data, @$re);
140
    }
141
  }
142
  foreach my $re (grep $_->[0] =~ /^countrycode$/, @{$regexes{$group}}) {
143
    $check_re->($group, $biller_data, @$re);
103 144
  }
104
  $check_re->($group, $biller_data, 'countrycode', qr{^[A-Z]{2}$});
105 145

  
106 146
  $group = 'payment information';
107
  $check_re->($group, $payment_information, 'amount', qr{^(?:(?:0|[1-9][0-9]{0,8})\.[0-9]{2})?$});
108
  $check_re->($group, $payment_information, 'currency', qr{^(?:CHF|EUR)$});
147
  foreach my $re (@{$regexes{$group}}) {
148
    $check_re->($group, $payment_information, @$re);
149
  }
109 150

  
110 151
  $group = 'invoice recipient data';
111
  $check_re->($group, $invoice_recipient_data, 'address_type', qr{^[KS]$});
112
  $check_re->($group, $invoice_recipient_data, 'name', qr{^.{1,70}$});
152
  foreach my $re (grep $_->[0] =~ /^(?:address_type|name)$/, @{$regexes{$group}}) {
153
    $check_re->($group, $invoice_recipient_data, @$re);
154
  }
113 155
  if ($invoice_recipient_data->{address_type} eq 'K') {
114
    $check_re->($group, $invoice_recipient_data, 'address_row1', qr{^.{0,70}$});
115
    $check_re->($group, $invoice_recipient_data, 'address_row2', qr{^.{0,70}$});
156
    foreach my $re (grep $_->[0] =~ /^address_row[12]$/, @{$regexes{$group}}) {
157
      $check_re->($group, $invoice_recipient_data, @$re);
158
    }
116 159
  } elsif ($invoice_recipient_data->{address_type} eq 'S') {
117
    $check_re->($group, $invoice_recipient_data, 'street', qr{^.{0,70}$});
118
    $check_re->($group, $invoice_recipient_data, 'street_no', qr{^.{0,16}$});
119
    $check_re->($group, $invoice_recipient_data, 'postalcode', qr{^.{0,16}$});
120
    $check_re->($group, $invoice_recipient_data, 'city', qr{^.{0,35}$});
160
    foreach my $re (grep $_->[0] =~ /^(?:street(?:_no)?|postalcode|city)$/, @{$regexes{$group}}) {
161
      $check_re->($group, $invoice_recipient_data, @$re);
162
    }
163
  }
164
  foreach my $re (grep $_->[0] =~ /^countrycode$/, @{$regexes{$group}}) {
165
    $check_re->($group, $invoice_recipient_data, @$re);
121 166
  }
122
  $check_re->($group, $invoice_recipient_data, 'countrycode', qr{^[A-Z]{2}$});
123 167

  
124 168
  $group = 'reference number data';
125 169
  my %ref_nr_regexes = (
126 170
    QRR => qr{^\d{27}$},
127 171
    NON => qr{^$},
128 172
  );
129
  $check_re->($group, $ref_nr_data, 'type', qr{^(?:QRR|SCOR|NON)$});
173
  foreach my $re (@{$regexes{$group}}) {
174
    $check_re->($group, $ref_nr_data, @$re);
175
  }
130 176
  $check_re->($group, $ref_nr_data, 'ref_number', $ref_nr_regexes{$ref_nr_data->{type}});
131 177
}
132 178

  

Auch abrufbar als: Unified diff