Auftrags-Controller: Speichern und schließen, …
[kivitendo-erp.git] / SL / Helper / QrBill.pm
index 3628056..c448eb2 100644 (file)
@@ -71,35 +71,44 @@ sub _init_check {
   my ($biller_information, $biller_data, $payment_information, $invoice_recipient_data, $ref_nr_data) = @_;
 
   my $check_re = sub {
-    my ($href, $elem, $regex) = @_;
+    my ($group, $href, $elem, $regex) = @_;
     defined $href->{$elem} && $href->{$elem} =~ $regex
-      or die "parameter '$elem' not valid", "\n";
+      or die "field '$elem' in group '$group' not valid", "\n";
   };
 
-  $check_re->($biller_information, 'iban', qr{^(?:CH|LI)[0-9a-zA-Z]{19}$});
-
-  $check_re->($biller_data, 'address_type', qr{^[KS]$});
-  $check_re->($biller_data, 'company', qr{^.{1,70}$});
-  $check_re->($biller_data, 'address_row1', qr{^.{0,70}$});
-  $check_re->($biller_data, 'address_row2', qr{^.{0,70}$});
-  $check_re->($biller_data, 'countrycode', qr{^[A-Z]{2}$});
-
-  $check_re->($payment_information, 'amount', qr{^(?:(?:0|[1-9][0-9]{0,8})\.[0-9]{2})?$});
-  $check_re->($payment_information, 'currency', qr{^(?:CHF|EUR)$});
-
-  $check_re->($invoice_recipient_data, 'address_type', qr{^[KS]$});
-  $check_re->($invoice_recipient_data, 'name', qr{^.{1,70}$});
-  $check_re->($invoice_recipient_data, 'address_row1', qr{^.{0,70}$});
-  $check_re->($invoice_recipient_data, 'address_row2', qr{^.{0,70}$});
-  $check_re->($invoice_recipient_data, 'countrycode', qr{^[A-Z]{2}$});
-
-  $check_re->($ref_nr_data, 'type', qr{^(?:QRR|SCOR|NON)$});
-  $check_re->($ref_nr_data, 'ref_number', qr{^\d{27}$});
+  my $group = 'biller information';
+  $check_re->($group, $biller_information, 'iban', qr{^(?:CH|LI)[0-9a-zA-Z]{19}$});
+
+  $group = 'biller data';
+  $check_re->($group, $biller_data, 'address_type', qr{^[KS]$});
+  $check_re->($group, $biller_data, 'company', qr{^.{1,70}$});
+  $check_re->($group, $biller_data, 'address_row1', qr{^.{0,70}$});
+  $check_re->($group, $biller_data, 'address_row2', qr{^.{0,70}$});
+  $check_re->($group, $biller_data, 'countrycode', qr{^[A-Z]{2}$});
+
+  $group = 'payment information';
+  $check_re->($group, $payment_information, 'amount', qr{^(?:(?:0|[1-9][0-9]{0,8})\.[0-9]{2})?$});
+  $check_re->($group, $payment_information, 'currency', qr{^(?:CHF|EUR)$});
+
+  $group = 'invoice recipient data';
+  $check_re->($group, $invoice_recipient_data, 'address_type', qr{^[KS]$});
+  $check_re->($group, $invoice_recipient_data, 'name', qr{^.{1,70}$});
+  $check_re->($group, $invoice_recipient_data, 'address_row1', qr{^.{0,70}$});
+  $check_re->($group, $invoice_recipient_data, 'address_row2', qr{^.{0,70}$});
+  $check_re->($group, $invoice_recipient_data, 'countrycode', qr{^[A-Z]{2}$});
+
+  $group = 'reference number data';
+  my %ref_nr_regexes = (
+    QRR => qr{^\d{27}$},
+    NON => qr{^$},
+  );
+  $check_re->($group, $ref_nr_data, 'type', qr{^(?:QRR|SCOR|NON)$});
+  $check_re->($group, $ref_nr_data, 'ref_number', $ref_nr_regexes{$ref_nr_data->{type}});
 }
 
 sub generate {
   my $self = shift;
-  my $out_file = defined $_[0] ? $_[0] : $Config{out_file};
+  my $out_file = $_[0] // $Config{out_file};
 
   $self->{qrcode} = $self->_qrcode();
   $self->{cross}  = $self->_cross();
@@ -113,8 +122,8 @@ sub _qrcode {
   my $self = shift;
 
   return Imager::QRCode->new(
-    size   =>  3,
-    margin =>  1,
+    size   =>  4,
+    margin =>  0,
     level  => 'M',
   );
 }
@@ -125,7 +134,7 @@ sub _cross {
   my $cross = Imager->new();
   $cross->read(file => $Config{cross_file}) or die $cross->errstr, "\n";
 
-  return $cross->scale(xpixels => 27, ypixels => 27, qtype => 'mixing');
+  return $cross->scale(xpixels => 35, ypixels => 35, qtype => 'mixing');
 }
 
 sub _plot {
@@ -193,7 +202,7 @@ SL::Helper::QrBill - Helper methods for generating Swiss QR-Code
          \%invoice_recipient_data,
          \%ref_nr_data,
        );
-       $qr_image->generate($outfile);
+       $qr_image->generate($out_file);
      } or do {
        local $_ = $@; chomp; my $error = $_;
        $::form->error($::locale->text('QR-Image generation failed: ' . $error));
@@ -311,7 +320,7 @@ Maximum of 4 characters, alphanumerical. QRR/SCOR/NON.
 
 =item C<ref_number>
 
-27 characters, numerical. QR-Reference.
+QR-Reference: 27 characters, numerical; without Reference: empty.
 
 =back