Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 29a13714

Von Moritz Bunkus vor fast 5 Jahren hinzugefügt

  • ID 29a13714c18417c2c8c3e62055ac6d67d0993e65
  • Vorgänger caaa4f67
  • Nachfolger f7bb8c5a

Kunden/Lieferanten: UStID-Nummern beim Speichern validieren

Unterschiede anzeigen:

SL/DB/Customer.pm
use SL::DB::Manager::Customer;
use SL::DB::Helper::IBANValidation;
use SL::DB::Helper::TransNumberGenerator;
use SL::DB::Helper::VATIDNrValidation;
use SL::DB::Helper::CustomVariables (
module => 'CT',
cvars_alias => 1,
......
my @errors;
push @errors, $::locale->text('The customer name is missing.') if !$self->name;
push @errors, $self->validate_ibans;
push @errors, $self->validate_vat_id_numbers;
return @errors;
}
SL/DB/Helper/VATIDNrValidation.pm
package SL::DB::Helper::VATIDNrValidation;
use strict;
use Carp;
use SL::Locale::String qw(t8);
use SL::VATIDNr;
my $_validator;
sub _validate {
my ($self, $attribute) = @_;
my $number = SL::VATIDNr->clean($self->$attribute);
return () unless length($number);
return () if SL::VATIDNr->validate($number);
return ($::locale->text("The VAT ID number '#1' is invalid.", $self->$attribute));
}
sub import {
my ($package, @attributes) = @_;
my $caller_package = caller;
@attributes = qw(ustid) unless @attributes;
no strict 'refs';
*{ $caller_package . '::validate_vat_id_numbers' } = sub {
my ($self) = @_;
return map { SL::DB::Helper::VATIDNrValidation::_validate($self, $_) } @attributes;
};
}
1;
__END__
=pod
=encoding utf8
=head1 NAME
SL::DB::Helper::VATIDNrValidation - Mixin for validating VAT ID number attributes
=head1 SYNOPSIS
package SL::DB::SomeObject;
use SL::DB::Helper::VATIDNrValidation [ ATTRIBUTES ];
sub validate {
my ($self) = @_;
my @errors;
push @errors, $self->validate_vat_id_numbers;
return @errors;
}
This mixin provides a function C<validate_vat_id_numbers> that returns
a list of error messages, one for each attribute that fails the VAT ID
number validation. If all attributes are valid or empty then an empty
list is returned.
The names of attributes to check can be given as an import list to the
mixin package. If no attributes are given the single attribute C<ustid>
is used.
=head1 FUNCTIONS
=over 4
=item C<validate_vat_id_numbers>
This function iterates over all configured attributes and validates
their content according to how VAT ID numbers are supposed to be
formatted in the European Union (or the enterprise identification
numbers in Switzerland). An attribute that is undefined, empty or
consists solely of whitespace is considered valid, too.
The function returns a list of human-readable error messages suitable
for use in a general C<validate> function (see SYNOPSIS). For each
attribute failing the check the list will include one error message.
If all attributes are valid then an empty list is returned.
=back
=head1 BUGS
Nothing here yet.
=head1 AUTHOR
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
=cut
SL/DB/Vendor.pm
use SL::DB::Manager::Vendor;
use SL::DB::Helper::IBANValidation;
use SL::DB::Helper::TransNumberGenerator;
use SL::DB::Helper::VATIDNrValidation;
use SL::DB::Helper::CustomVariables (
module => 'CT',
cvars_alias => 1,
......
my @errors;
push @errors, $::locale->text('The vendor name is missing.') if !$self->name;
push @errors, $self->validate_ibans;
push @errors, $self->validate_vat_id_numbers;
return @errors;
}
locale/de/all
'The SQL query can be parameterized with variables named as follows: <%name%>.' => 'Die SQL-Abfrage kann mittels Variablen wie folgt parametrisiert werden: <%Variablenname%>.',
'The SQL query does not contain any parameter that need to be configured.' => 'Die SQL-Abfrage enthält keine Parameter, die angegeben werden müssten.',
'The URL is missing.' => 'URL fehlt',
'The VAT ID number \'#1\' is invalid.' => 'Die UStID-Nummer »#1« ist ungültig.',
'The VAT registration number is missing in the client configuration.' => 'Die Umsatzsteuer-ID-Nummer fehlt in der Mandantenkonfiguration.',
'The WebDAV feature has been used.' => 'Das WebDAV-Feature wurde benutzt.',
'The XMP metadata does not declare the ZUGFeRD data.' => 'Die XMP-Metadaten enthalten keine ZUGFeRD-Deklaration.',

Auch abrufbar als: Unified diff