Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 64ba4cbb

Von Cem Aydin vor etwa 2 Jahren hinzugefügt

  • ID 64ba4cbb6e30476f4f442d09bf4d0b1d3e121bab
  • Vorgänger 744958b4
  • Nachfolger db101cc6

Swiss QR-Bill: QrBillFunctions.pm Fehlerrückgabe angepasst

Unterschiede anzeigen:

SL/Helper/QrBillFunctions.pm
19 19
  $qr_account = first { $_->use_for_qrbill } @{ $bank_accounts };
20 20

  
21 21
  if (!$qr_account) {
22
    $::form->error($::locale->text('No bank account flagged for QRBill usage was found.'));
22
    return undef, $::locale->text('No bank account flagged for QRBill usage was found.');
23 23
  }
24 24

  
25 25
  $main::lxdebug->leave_sub();
26
  return $qr_account;
26
  return $qr_account, undef;
27 27
}
28 28

  
29 29
sub assemble_ref_number {
......
39 39
  #     input: 6 digits, only numbers
40 40
  #     output: 6 digits, only numbers
41 41
  if (!($bank_id =~ /^\d*$/) || length($bank_id) != 6) {
42
    $::form->error($::locale->text('Bank account id number invalid. Must be 6 digits.'));
42
    return undef, $::locale->text('Bank account id number invalid. Must be 6 digits.');
43 43
  }
44 44

  
45 45
  # - customer_number
......
47 47
  #     output: prefix removed, 6 digits, filled with leading zeros
48 48
  $customer_number = remove_letters_prefix($customer_number);
49 49
  if (!check_digits_and_max_length($customer_number, 6)) {
50
    $::form->error($::locale->text('Customer number invalid. Must be less then or equal to 6 digits after prefix.'));
50
    return undef, $::locale->text('Customer number invalid. Must be less then or equal to 6 digits after non-digits removed.');
51 51
  }
52 52
  # fill with zeros
53 53
  $customer_number = sprintf "%06d", $customer_number;
......
57 57
  #     output: prefix removed, 7 digits, filled with leading zeros
58 58
  $order_number = remove_letters_prefix($order_number);
59 59
  if (!check_digits_and_max_length($order_number, 7)) {
60
    $::form->error($::locale->text('Order number invalid. Must be less then or equal to 7 digits after prefix.'));
60
    return undef, $::locale->text('Order number invalid. Must be less then or equal to 7 digits after prefix.');
61 61
  }
62 62
  # fill with zeros
63 63
  $order_number = sprintf "%07d", $order_number;
......
67 67
  #     output: prefix removed, 7 digits, filled with leading zeros
68 68
  $invoice_number = remove_letters_prefix($invoice_number);
69 69
  if (!check_digits_and_max_length($invoice_number, 7)) {
70
    $::form->error($::locale->text('Invoice number invalid. Must be less then or equal to 7 digits after prefix.'));
70
    return undef, $::locale->text('Invoice number invalid. Must be less then or equal to 7 digits after prefix.');
71 71
  }
72 72
  # fill with zeros
73 73
  $invoice_number = sprintf "%07d", $invoice_number;
......
79 79
  my $ref_number_cpl = $ref_number . calculate_check_digit($ref_number);
80 80

  
81 81
  $main::lxdebug->leave_sub();
82
  return $ref_number_cpl;
82
  return $ref_number_cpl, undef;
83 83
}
84 84

  
85 85
sub get_ref_number_formatted {
......
122 122
  $main::lxdebug->enter_sub();
123 123

  
124 124
  unless ($_[0] =~ /^\d+\.\d{2}$/) {
125
    $::form->error($::locale->text('Amount has wrong format.'));
125
    return undef;
126 126
  }
127 127

  
128 128
  local $_ = shift;
......
182 182
    get_ref_number_formatted get_iban_formatted get_amount_formatted);
183 183

  
184 184
  # get qr-account data
185
  my $qr_account = get_qrbill_account();
185
  my ($qr_account, $error) = get_qrbill_account();
186 186

  
187
  my $ref_number = assemble_ref_number(
187
  my ($ref_number, $error) = assemble_ref_number(
188 188
    $qr_account->{'bank_account_id'},
189 189
    $form->{'customernumber'},
190 190
    $form->{'ordnumber'},
......
197 197
  $form->{'iban_formatted'} = get_iban_formatted($qr_account->{'iban'});
198 198

  
199 199
  # format amount for template
200
  $form->{'amount_formatted'} = get_amount_formatted(
201
    sprintf(
202
      "%.2f",
203
      $form->parse_amount(\%::myconfig, $form->{'total'})
204
    )
205
  );
200
  my $amount = sprintf("%.2f", $form->parse_amount(\%::myconfig, $form->{'total'}));
201
  my $amount_formatted = get_amount_formatted($amount);
206 202

  
207 203
=head1 DESCRIPTION
208 204

  
......
214 210

  
215 211
=item C<get_qrbill_account>
216 212

  
217
Return the bank account flagged for the QR bill.
213
Return the bank account flagged for the QR bill. And a string containing an
214
error message as second return value or undef if no error occurred.
218 215

  
219 216
=item C<assemble_ref_number>
220 217

  
221 218
Assembles and returns the Swiss reference number. 27 digits, formed
222
from the parameters plus one check digit.
219
from the parameters plus one check digit. And a string containing an error
220
message as second return value or undef if no error occurred.
223 221

  
224 222
Prefixes will be removed and numbers filled up with leading zeros.
225 223

  
......
260 258
=item C<get_amount_formatted>
261 259

  
262 260
Given an amount, return it in format: 'X XXX.XX'
261
Or undef if an error occurred.
263 262

  
264 263
=back
265 264

  
266 265
=head1 ERROR HANDLING
267 266

  
268
Currently errors are thrown via form e.g.:
267
The functions C<get_qrbill_account> and C<assemble_ref_number> return
268
undef when an error occurs and a string containing an error message as
269
second return value.
270

  
271
The function C<get_amount_formatted> returns undef if an error occurred.
269 272

  
270
  $::form->error($::locale->text('Bank account id number invalid. Must be 6 digits.'));
273
The other functions always return a result.
271 274

  
272 275
=head1 AUTHOR
273 276

  
SL/Template/OpenDocument.pm
482 482
  # assemble data for QR-Code
483 483

  
484 484
  # get qr-account data
485
  my $qr_account = get_qrbill_account();
485
  my ($qr_account, $error) = get_qrbill_account();
486
  if (!$qr_account) {
487
    $::form->error($error);
488
  }
486 489

  
487 490
  my %biller_information = (
488 491
    'iban' => $qr_account->{'iban'}
......
501 504
    'countrycode' => $biller_countrycode,
502 505
  );
503 506

  
504
  my $amount;
507
  my ($amount, $amount_formatted);
505 508
  if ($form->{'qrbill_without_amount'}) {
506 509
    $amount = '';
510
    $amount_formatted = '';
507 511
  } else {
508 512
    $amount = sprintf("%.2f", $form->parse_amount(\%::myconfig, $form->{'total'}));
513

  
514
    # format amount for template
515
    $amount_formatted = get_amount_formatted($amount);
516
    if (!$amount_formatted) {
517
      $::form->error($::locale->text('Amount has wrong format.'));
518
    }
509 519
  }
510 520

  
511 521
  my %payment_information = (
......
529 539
  my %ref_nr_data;
530 540
  if ($::instance_conf->get_create_qrbill_invoices == 1) {
531 541
    # generate ref.-no. with check digit
532
    my $ref_number = assemble_ref_number(
542
    my ($ref_number, $error) = assemble_ref_number(
533 543
      $qr_account->{'bank_account_id'},
534 544
      $form->{'customernumber'},
535 545
      $form->{'ordnumber'},
536 546
      $form->{'invnumber'},
537 547
    );
548
    if (!$ref_number) {
549
      $::form->error($error);
550
    }
538 551
    %ref_nr_data = (
539 552
      'type' => 'QRR',
540 553
      'ref_number' => $ref_number,
......
556 569
  $form->{'biller_information'} = \%biller_information;
557 570
  $form->{'biller_data'} = \%biller_data;
558 571
  $form->{'iban_formatted'} = get_iban_formatted($qr_account->{'iban'});
559

  
560
  # format amount for template
561
  $form->{'amount_formatted'} = get_amount_formatted(
562
    sprintf(
563
      "%.2f",
564
      $form->parse_amount(\%::myconfig, $form->{'total'})
565
    )
566
  );
567

  
572
  $form->{'amount_formatted'} = $amount_formatted;
573
  
568 574
  # set outfile
569 575
  my $outfile = $form->{"tmpdir"} . '/' . 'qr-code.png';
570 576

  

Auch abrufbar als: Unified diff