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 |
|
Swiss QR-Bill: QrBillFunctions.pm Fehlerrückgabe angepasst